Skip to content
Docker β€’ β€’ 1 min read

How to Change the Storage Directory in Docker

How to Change the Storage Directory in Docker

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