Overview
This guide explains how to change Docker's default container deployment path from /var/lib/docker to a custom directory.
This process involves stopping Docker services, creating a new directory, migrating existing data, and updating Docker configuration.
| Note: Please take the necessary snapshot before performing the activity. |
Configuration Steps
1: Stop the Docker services.
| systemctl stop docker |
2: Create the Directory with proper permissions where it's required.
mkdir -p /docker_data chown root:root /docker_data chmod 711 /docker_data |
3: If it's an existing environment, follow the steps below.
If it's a new environment and you have not deployed any containers yet, you can skip to step 4
| rsync -aP /var/lib/docker/ /docker_data/ |
4: Create or add the content in the JSON file (vi /etc/docker/daemon.json).
{ "data-root": "/docker_data" } |
5: Restart the Docker services.
| systemctl start docker |
Verification
To verify the custom path of containers:
| docker info | grep 'Docker Root Dir' |
Output
| Docker Root Dir: /docker_data |
Cleanup
If required, you can remove the old data located in /var/lib/docker to utilize the space.
Comments
0 comments
Please sign in to leave a comment.