This topic describes how to mount a data disk to the Docker data directory. When the disk space is insufficient to support an increase in the number of containers or images on a node, you can mount a data disk to the Docker data directory. This provides more storage space to create containers and store images.
Docker data directory
# du -h --max-depth=0 /var/lib/docker 7.9G /var/lib/docker
A Docker image may be large in size. A few images may occupy a large amount of disk space. The disk capacity may be insufficient if you create large-sized images or a large number of containers. In this case, you must mount a data disk to the Docker data directory. This allows you to create more images or containers.
Mount a data disk
To mount a disk to the Docker data directory, perform the following steps:
- Create a data disk and mount it to the node for which you want to expand the disk.
For more information, see Create a disk.
- Log on to the Elastic Compute Service (ECS) console and create the required disk.
- In the left-side navigation pane, click Instances.
- On the Instances page, click the ID of the ECS instance that you want to manage. Then, you are directed to the Instance Details page.
- On the Instance Details page, click the Cloud Disk tab.
- On the Cloud Disk tab, click Attach Disk in the upper-right corner of the page.
- In the dialog box that appears, select a disk from the Target Disk drop-down list. Click OK.
- Click Attach to attach the disk to the specified ECS instance, and record the mount point
- Log on to the ECS instance and format the mounted disk.
- In the command-line interface (CLI), enter ls -l /dev/xvd* or ls -l /dev/vd* to check whether the returned mount point is the same as what you have recorded.
- In the CLI, enter fdisk to partition the disk and enter mkfs.ext4 to format the disk.
- Migrate the Docker data to the disk. If you do not want to suspend the applications that run on the node, you must migrate the applications. For more information about how to migrate applications that run in a Swarm cluster, see Schedule an application to specified nodes. For more information about how to migrate applications that run in a Kubernetes cluster, see Safely Drain a Node while Respecting Application SLOs.
- To ensure data integrity during the migration process, stop Docker daemon and kubelet. Enter service docker stop in the CLI to stop Docker daemon and enter service kubelet stop to stop kubelet.
- Move the Docker data directory to a backup directory, such as mv /var/lib/docker /var/lib/docker_data.
- Mount the formatted disk to the /var/lib/docker and /var/lib/kubelet directories. Examples:
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 Docker data that has been backed up to the formatted disk, such as mv /var/lib/docker_data/* /var/lib/docker/.
- Start Docker daemon and kubelet, and check where the data is stored.
- In the CLI, enter service docker start to start Docker daemon and enter service kubelet start to start kubelet.
- In the CLI, enter df to check whether /var/lib/docker has been mounted to the disk. If you want to start the Kubernetes cluster, skip this
- In the CLI, enter docker ps to check whether containers are lost. Restart containers as required. For example,
you can restart containers that do not have the
- If a container has been migrated to other nodes, you can schedule it back to the node
to which you have attached the disk.
For more information, see Container Service for Kubernetes.