If you use Docker to manage containers, at some point, you may need to change the directory where Docker stores its data. This could be due to low disk space or simply for better organization. The good news? It's easy to do! Let's go! π
π Step 1: Editing the Docker Configuration
To change Dockerβs storage directory, we need to edit its daemon configuration file. Open the terminal and run:
vim /etc/docker/daemon.json
If the file does not exist, create it. Then, add or modify the following lines:
{
"data-root": "/new/docker/storage/path"
}
Replace /new/docker/storage/path
with the new directory where you want to store Dockerβs data.
β Step 2: Stopping Containers and Cleaning Up Old Data
Before applying the change, we need to stop all containers and remove old data to prevent conflicts. Run:
docker ps -a -q | xargs docker stop
docker system prune -a
π Step 3: Restarting Docker
Now, restart Docker to apply the new storage configuration:
systemctl restart docker
To ensure that Docker is using the correct path, verify its status:
systemctl status docker
π Step 4: Verifying the Change
To check if the new storage directory is in use, run:
docker info | grep "Docker Root Dir"
If the output displays the path you configured in daemon.json
, youβre all set! π
π‘ Who am I?
I'm Gabriel Carmo, a tech enthusiast (especially Open Source). I have experience with Cloud, Kubernetes, OpenShift, Zabbix, Dynatrace, and more! Always exploring new technologies and sharing knowledge. π
π¬ Letβs connect?
π LinkedIn
π GitHub
π¦ GitLab
π
Credly
π§ Contact: contato@gabrielandre.com.br