Docker data direcory

How to move docker data direcory to a different location in ubuntu.

Andrea Spano andreaspano.github.io (Quantide)www.quantide.com
2020-09-20

The default data directory used by docker system for storing images is /var/lib/docker. You may want to move this directory to another location on your system.

This goal can be achieved by following the next steps:

  1. Stop the docker daemon

sudo service docker stop`
  1. Add a configuration file named daemon.json under the directory /etc/docker. The file should have this content:

{ 
   "graph": "/path/to/your/docker" 
}
  1. Copy the current data directory to the new one

sudo rsync -aP /var/lib/docker/ /path/to/your/docker
  1. Rename the old docker directory

sudo mv /var/lib/docker /var/lib/docker.old
  1. Restart the docker daemon

sudo service docker start
  1. Test

Create a new doocker and check that a new image appears in /path/to/your/docker

  1. Cleanup

When you are sure that the new directory is being used correctly by docker daemon you can delete the old data directory.


sudo rm /var/lib/docker

insights

Please check (Destrero 2020) for more detailed tutorial on this topic

Destrero, Augusto. 2020. “How to Move Docker Data Directory to Another Location on Ubuntu.” https://www.guguweb.com/2019/02/07/how-to-move-docker-data-directory-to-another-location-on-ubuntu/.

References

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Citation

For attribution, please cite this work as

Spano (2020, Sept. 20). andreaspano blog: Docker data direcory. Retrieved from https://andreaspano.github.io/posts/2020-09-20-how-to-move-docker-data-direcory/

BibTeX citation

@misc{spano2020docker,
  author = {Spano, Andrea},
  title = {andreaspano blog: Docker data direcory},
  url = {https://andreaspano.github.io/posts/2020-09-20-how-to-move-docker-data-direcory/},
  year = {2020}
}