Profile Applicability:
Level 1
Description:
Docker stores container data by default under /var/lib/docker. To prevent issues such as disk space exhaustion, it is recommended to create a separate partition for Docker data. This ensures Docker containers are isolated from the main system and do not affect system performance.
Rationale:
Storing Docker data on a separate partition ensures that Docker containers do not fill up the root file system, preventing potential downtime or system issues due to lack of disk space. A dedicated partition improves resource management and security by isolating Docker-related files from other system files.
Impact:
Pros:
Ensures better resource management by separating Docker data from the host file system.
Prevents Docker data from consuming all available space on the root filesystem.
Cons:
Requires partitioning or resizing disk space, which could cause downtime if not planned properly.
Some configurations may require additional setup for mounting and ensuring Docker persists across reboots.
Default Value:
By default, Docker uses /var/lib/docker which is typically stored on the same partition as the root file system.
Pre-requisites:
Disk partitioning tools available (e.g., LVM, fdisk).
Administrative privileges to modify disk partitions and mount points.
Remediation:
Test Plan:
Using AWS Console:
- Navigate to the EC2 instance running Docker.
- Use df -h to check the current disk usage and confirm that /var/lib/docker is on a separate partition.
- Ensure the partition is not shared with other files or directories by reviewing the mount or lsblk output.
Using AWS CLI:
- Connect to the EC2 instance running Docker.
- Run df -h to verify the disk partitions and ensure that Docker is using a dedicated partition.
Implementation Plan:
Using AWS Console:
- Log in to the EC2 instance.
- Create a new partition using LVM or a tool like fdisk and mount it to /var/lib/docker.
- Modify /etc/fstab to ensure the new partition is mounted on reboot.
- Restart Docker to ensure the changes take effect:
sudo systemctl restart docker
Using AWS CLI:
- Use SSM to remotely create a new partition and mount it for Docker storage.
- Execute the following command to partition and mount the disk:
aws ssm send-command --document-name "AWS-RunShellScript" --targets "Key=instanceIds,Values=instance_id" --parameters 'commands=["sudo lvcreate -L 10G -n docker_data docker_vg && sudo mkfs.ext4 /dev/docker_vg/docker_data && sudo mount /dev/docker_vg/docker_data /var/lib/docker && sudo systemctl restart docker"]'
Backout Plan:
Using AWS Console:
- Connect to the EC2 instance.
- Unmount the partition using sudo umount /var/lib/docker.
- Optionally, remove the partition or restore the default Docker storage configuration by editing /etc/fstab and rebooting.
- Restart Docker:
sudo systemctl restart docker
Using AWS CLI:
- Use SSM to remove the partition and revert Docker storage to the default location.
- Execute the following command:
aws ssm send-command --document-name "AWS-RunShellScript" --targets "Key=instanceIds,Values=instance_id" --parameters 'commands=["sudo umount /var/lib/docker && sudo rm -rf /var/lib/docker/* && sudo systemctl restart docker"]'
References:
CIS Docker Benchmark v1.7
Docker Storage Documentation: https://docs.docker.com/storage/