Breadcrumbs

Change Docker default directory

The following config will guide you through a process of changing the docker's default /var/lib/docker storage disk space to another directory.

  1. Login to CentOS and edit or create /etc/docker/daemon.json

  2. Add the following piece of code to the file you have just opened:


    1. {
      "data-root": "/home/var"  
      }
      
      
      


  3. Stop the docker service using 


    1. Bash
      systemctl stop docker
      


  4. Wait for sometime for all the docker containers to shutdown gracefully

  5. Reload the systemd configuration for  new changes to be effective.


    1. Bash
      systemctl daemon-reload
      
      
      


  6. Create the new directory to be the new home for docker service. For example, if you want /home/var to be the home for Docker service, create the directory by using following command.

  7. Copy or sync all the current containers to the new root directory for docker.


    1. Bash
      rsync -aqxP /var/lib/docker/ /home/var
      


  8. Start the docker service daemon 

  9. That's it. If you have done everything correctly, Docker service should be started normally. Verify all the containers are up and running successfully by running following command. docker ps -a