Search code examples
dockerdocker-composedocker-machine

Move Docker /var/run/docker data to different directory


I followed the following tutorial to transfer and permanently move where docker saves data previously inside /usr/bin: https://linuxconfig.org/how-to-move-docker-s-default-var-lib-docker-to-another-directory-on-ubuntu-debian-linux

However upon restarting docker and rebuilding all containers, there seems to be activity in /var/run/docker/containerd/ which I was previously trying to work around. I was hoping to have all things docker saved in a specific directory not in /var/run along with my newly created docker directory to replace /usr/bin/docker

Note: df -h did in fact prove that I am out of space in the base directory where /usr/bin and /var/run exists. I am trying to navigate all docker items to a sub directory under /opt

How do I move all things Docker to a different directory?

(Answer) Found in documentation: https://docs.docker.com/config/daemon/systemd/#runtime-directory-and-storage-driver


Solution

  • As described in the Docker documentation, to set the docker daemon directory to <folder>:

    Create /etc/docker/daemon.json with the following contents:

    {
        "data-root": "<folder>",
        "storage-driver": "overlay2"
    }
    

    Restart the docker daemon.

    Note that this will not move existing docker data over to the target folder - you will need to handle that (or start from scratch).