Change Docker Default Directory
In Docker, you can set the default directory for Docker by modifying the daemon.json configuration file. By default, Docker’s data and configuration files are stored in the /var/lib/docker directory, but you can specify a different directory as the default for Docker by modifying the daemon.json file.
Here are the steps to configure the default directory for Docker:
- Open the Docker configuration file daemon.json. This file is typically located in the /etc/docker/ directory, but if it cannot be found, you can create a new file.
- Add the following content to the daemon.json file to specify a new default directory:
{
"data-root": "/path/to/docker"
}
Replace “/path/to/docker” with the directory path where you want to store Docker data and configuration files.
- Save and close the daemon.json file.
- Restart the Docker service to apply the changes.
sudo systemctl restart docker
Docker will now use a newly specified directory as the default directory for storing data and configuration files. Please be aware that changing the default directory may require some additional configuration and permission settings to ensure the new directory has enough space and appropriate permissions to run Docker containers.