This topic describes how to mount a disk to the Docker data directory. If the number of containers or images that run on an ECS instance increases constantly, the ECS instance disk capacity may be insufficient. In this case, you can expand the Docker data directory by mounting a disk to the ECS instance.
Docker data directory
# du -h --max-depth=0 /var/lib/docker 7.9G /var/lib/docker
Generally, a Docker image occupies a large amount of disk space. If you want to use multiple Docker images or a large number of containers, you must mount a disk to the Docker data directory to ensure sufficient disk capacity is available.
Mount a disk
To mount a disk to the Docker data directory, follow these steps:
- Create a disk and mount it to the target ECS instance for which you want to expand
the disk capacity.
- Log on to the ECS console to create a disk.
- In the left-side navigation pane, click Instances.
- Click the target ECS instance ID.
- In the left-side navigation pane, click Disks.
- In the upper-right corner, click Mount.
- In the displayed dialog box, select the created disk from the target disk drop-down list, and then click OK.
- Click Mount to mount the new disk to the target ECS instance, and record the new disk mounting
point which is in the format of
- Log on to the target ECS instance to format the new disk.
- Run the ls -l /dev/xvd* or ls -l /dev/vd* command to verify whether a disk that has the recorded mounting point has been mounted to the ECS instance.
- Run the fdisk command to partition the new disk, and then run the mkfs.ext4 command to format the new disk.
- Migrate the Docker data to the new disk.
If you do not want to suspend the applications that run on the target ECS instance, you must migrate the applications. For how to migrate applications on a Swarm cluster, see Schedule an application to specified nodes. For how to migrate applications on a Kubernetes cluster, see Safely drain a node while respecting application SLOs.
- To ensure that data can be migrated, run the service docker stop command to stop Docker daemon, and run the service kubelet stop command to stop kubelet.
- Migrate the Docker directory data to a backup directory. For example, mv /var/lib/docker /var/lib/docker_data.
- Mount the new disk to the /var/lib/docker and /var/lib/kubelet directories. For example,
echo "/dev/xvdb1 /var/lib/container/ ext4 defaults 0 0" >>/etc/fstab echo "/var/lib/container/kubelet /var/lib/kubelet none defaults,bind 0 0" >>/etc/fstab echo "/var/lib/container/docker /var/lib/docker none defaults,bind 0 0" >>/etc/fstab mkdir /var/lib/docker mount -a
- Migrate the backed up Docker data to the new disk. For example, mv /var/lib/docker_data/* /var/lib/docker/.
- Start the Docker daemon and kubelet, and check the data location.
- Run the service docker start command to start the Docker daemon, and run the service kubelet start command to start kubelet.
- Run the df command to verify whether /var/lib/docker has been mounted to the new disk. If you need to start the Kubernetes cluster, skip this step.
- Run the docker ps command to check whether containers are lost. Restart containers as needed. For example,
you can restart a container that has not been set the
- If a container has been migrated to other nodes, you can schedule it back to the target node to which you mounted the new disk.
For more information, see Container Service.