Leia este artigo em português.
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.jsonIf 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 dockerTo 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 CNCF Kubestronaut holding the CKA, CKAD, CKS, KCNA, and KCSA certifications, as well as Red Hat Certified OpenShift Administrator.
I work in DevOps Engineering, building and evolving multi-cloud Kubernetes platforms. My work focuses on reducing engineering teams’ cognitive load through platform engineering, automation, GitOps, and self-service experiences.
In my daily work, I connect infrastructure as code, cloud networking, governance, security, observability, and SRE practices to build more standardized, resilient, and operable platforms.