How to change the default storage path of Docker?

To change the default storage path of Docker, you can follow these steps:

  1. Stop the Docker service.
  2. On a Linux system, you can use the following command to stop the Docker service: sudo systemctl stop docker
  3. On a Windows system, you can locate the Docker icon in the system tray, right-click on it, and select the “Exit” option.
  4. Copy Docker’s default storage directory to a new location.
  5. By default, Docker’s storage directory is /var/lib/docker (Linux system) or C:\ProgramData\Docker (Windows system).
  6. Copy the default storage directory to a new location (such as /new/docker) using the following command: sudo rsync -aP /var/lib/docker/ /new/docker/
  7. Edit the configuration file for Docker.
  8. You can edit Docker’s configuration file on a Linux system using the following command: sudo nano /etc/docker/daemon.json.
  9. You can find the daemon.json file in the Docker installation directory on Windows system and open it using a text editor.
  10. Modify the data-root parameter in the configuration file to a new storage path.
  11. In the daemon.json file, change the value of the data-root parameter to the new storage path (e.g. /new/docker): {
    “data-root”: “/new/docker”
    }
  12. Save and close the configuration file.
  13. Start the Docker service.
  14. On Linux systems, the following command can be used to start the Docker service: sudo systemctl start docker
  15. You can restart the Docker application on a Windows system.

Now, Docker will utilize a new storage path to store files such as images, containers, and data volumes.

bannerAds