How to Change Docker Storage Directory

To change the storage directory of Docker, you need to edit Docker’s configuration file and restart the Docker service. Here are the simple steps to change the Docker storage directory on a Linux system:

  1. Stop the Docker service.
sudo service docker stop
  1. Folder for newly created Docker images/containers.
sudo mkdir /new/docker/directory
  1. The configuration file for Docker located at /etc/docker/daemon.json
sudo vi /etc/docker/daemon.json

Add the following content to the configuration file, replacing /new/docker/directory with the desired new storage directory.

{
    "data-root": "/new/docker/directory"
}
  1. Save and close the configuration file, then restart the Docker service.
sudo service docker start

Now that you have successfully changed the Docker storage directory, you can verify if the new directory is effective by running the following command in the terminal:

docker info | grep "Docker Root Dir"

You should be able to see the new storage directory path displayed in the output.

bannerAds