How to change the default storage path of Docker?
To change the default storage path of Docker, you can follow these steps:
- Stop the Docker service.
- On a Linux system, you can use the following command to stop the Docker service: sudo systemctl stop docker
- On a Windows system, you can locate the Docker icon in the system tray, right-click on it, and select the “Exit” option.
- Copy Docker’s default storage directory to a new location.
- By default, Docker’s storage directory is /var/lib/docker (Linux system) or C:\ProgramData\Docker (Windows system).
- 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/
- Edit the configuration file for Docker.
- You can edit Docker’s configuration file on a Linux system using the following command: sudo nano /etc/docker/daemon.json.
- You can find the daemon.json file in the Docker installation directory on Windows system and open it using a text editor.
- Modify the data-root parameter in the configuration file to a new storage path.
- 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”
} - Save and close the configuration file.
- Start the Docker service.
- On Linux systems, the following command can be used to start the Docker service: sudo systemctl start docker
- 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.