How to add a data disk to a container service Docker
Absrtact: We know that docker data is stored on the disk through a federated file system, and when the number of containers or mirrors that need to run on the machine is increasing, it is possible that the size of the disk will no longer meet the requirements, and that the Docker data directory will need to be expanded by increasing the data disk.
Docker Data Catalog
Docker default container and mirror data store directory is under /var/lib/docker , you can use the DU command to see the size of the disk currently occupied by this directory, for example:
du -H--max-depth=0 /var/lib/Docker7. 9G /var/lib/docker
Replace the Docker data disk
Because many of the Docker image itself is quite large, so may not be able to use a few mirrors will have a considerable disk footprint, the container will lead to insufficient disk space, this time how to replace the data disk to meet the need to increase the image or container, then the Docker Data directory to add a block of data disk bar.
Purchase the ECS data disk and mount it on the machine that needs to be expanded: 1. Purchase the required configuration Cloud Disk 2 via the ECS console. On the ECS Instance Details page, this instance disk-mounted disk, select the disk you just purchased, and record the mount point
/dev/xvd*
Or
/dev/vd*
Log on to the machine and format the disk you just mounted: 1. First, execute on the machine.
ls -l /dev/xvd*
Or
ls -l /dev/vd*
See the same disk Id2 as just recorded. Partition the disk with the Fdisk command, and then use the
MKFS.EXT4Format the disk, for example:
Move Docker data to the new disk: 1. First stop the Docker daemon, ensure that the data is complete when moving, you can use
service docker stop
Command Stop 2. First move the Docker directory to a backup directory, for example:
mv /var/lib/docker /var/lib/docker_data
3. Then mount the new formatted disk to
/var/lib/docker
directories, such as:
echo "/dev/xvdb1 /var/lib/docker ext4 defaults 0 0" >>/etc/fstab && mkdir /var/lib/docker && mount -a
4. Move the previously backed-up Docker data to a new disk, for example:
mv /var/lib/docker_data/* /var/lib/docker/
Start the Docker daemon and check the data location: 1. Start Docker Daemon,
service docker start
2. Implementation
df
See the/var/lib/docker mounted on the new disk
3.
docker ps
See that the container is not missing, restart as needed to start without
restart:always
Container for labels
How to add a data disk to a container service Docker