To change where Docker installs images, we need to set up the Docker daemon settings. This means we will specify a new path for storing images. We can do this by changing the Docker daemon configuration file or by using command-line options. Following these steps helps us manage the Docker image installation directory and use our system’s storage better.
In this article, we will look at different ways to change the Docker image installation directory on various operating systems. We will talk about the default installation directory. We will also see how to set up the Docker daemon and use Docker configuration files. Plus, we will give clear steps for changing the Docker image installation directory on Linux and Windows systems. Here’s what we will cover:
- Understanding the Default Docker Image Installation Directory
- Configuring Docker Daemon to Change Image Installation Directory
- Using Docker Configuration Files to Set Image Installation Path
- Changing the Docker Image Installation Directory on Linux Systems
- Changing the Docker Image Installation Directory on Windows Systems
- Frequently Asked Questions
For more information about Docker, you can look at other articles like What is Docker and Why Should You Use It and How to Install Docker on Different Operating Systems.
Understanding the Default Docker Image Installation Directory
By default, Docker saves images, containers, and other data in the
/var/lib/docker
folder on Linux systems. This folder has
different subfolders for images, containers, volumes, and networks. The
structure looks like this:
/var/lib/docker
├── containers
├── image
├── volumes
└── networks
On Windows, Docker uses a different path. It is usually found at
C:\ProgramData\Docker
. This folder also has similar
subfolders to manage Docker’s resources.
Knowing this default path is important when we want to change where Docker stores its images. It helps us see where Docker keeps its files. It also shows us how to set up a new installation folder correctly.
If we want to move the Docker installation folder, we need to stop Docker first. Then, we should copy existing data from the default folder to the new one. It is important to keep the same folder structure to avoid problems with Docker working right.
Configuring Docker Daemon to Change Image Installation Directory
We can change the Docker image installation directory by configuring
the Docker daemon. This means we need to edit the Docker configuration
file. This file is usually found at /etc/docker/daemon.json
on Linux. For Windows, it is at
%programdata%\docker\config\daemon.json
.
Steps for Linux
Open the Docker daemon configuration file:
sudo nano /etc/docker/daemon.json
Add or change the
data-root
property to set the new installation directory. For example:{ "data-root": "/mnt/docker-data" }
Save and exit the editor. If you use nano, press
CTRL+X
, thenY
, and thenEnter
.Restart the Docker service so the changes take effect:
sudo systemctl restart docker
Steps for Windows
Open the Docker daemon configuration file:
- Go to
%programdata%\docker\config\daemon.json
. - If the file is not there, make a new one.
- Go to
Add or change the
data-root
property:{ "data-root": "D:\\DockerData" }
Save the file and restart Docker Desktop. You can do this by right-clicking the system tray icon and selecting “Quit Docker Desktop”. Then, open it again.
Verification
To check if the changes worked:
Run this command to see the current Docker configuration:
docker info | grep "Docker Root Dir"
This command will show the current Docker root directory. It helps us to know if the changes we made were successful. Changing the Docker daemon settings can help us manage disk space and improve performance by moving images and containers to a better storage place.
Using Docker Configuration Files to Set Image Installation Path
To change the Docker image installation path, we need to modify the
Docker daemon’s settings. We can do this by editing the
daemon.json
file. Here are the steps to set the image
installation path:
Find the
daemon.json
file:- On Linux, we usually find this file at
/etc/docker/daemon.json
. - On Windows, it is often located at
C:\ProgramData\docker\config\daemon.json
.
- On Linux, we usually find this file at
Edit the
daemon.json
file: We should open the file in a text editor. Then we add or change the following JSON settings:{ "data-root": "/new/path/to/docker" }
We need to replace
/new/path/to/docker
with the directory where we want to store Docker images.Restart the Docker service: After we save the changes in the
daemon.json
file, we must restart the Docker service to apply the changes.On Linux, we can use this command:
sudo systemctl restart docker
On Windows, we can restart Docker from the Docker Desktop app or use:
Restart-Service docker
Check the configuration: After we restart Docker, we can check if it is using the new installation path by running:
docker info | grep "Docker Root Dir"
This way, we change the Docker image installation path by updating the config file. Now, all new Docker images will be stored in the new path. For more information on Docker config, you can look at what is Docker and why should you use it.
Changing the Docker Image Installation Directory on Linux Systems
To change the Docker image installation directory on Linux systems,
we need to set up the Docker daemon. By default, Docker saves images in
the /var/lib/docker
directory. Let’s see how we can change
this directory.
Stop the Docker Service:
First, we should stop the Docker service. This makes sure that no processes are using the Docker directory.sudo systemctl stop docker
Create a New Directory:
Now, we can create a new directory where we want Docker to keep its images, containers, and volumes.sudo mkdir /path/to/new/docker
Copy Existing Data (Optional):
If we want to keep our current Docker data, we can copy it to the new directory.sudo rsync -aP /var/lib/docker/ /path/to/new/docker/
Configure the Docker Daemon:
Next, we need to edit the Docker service configuration file to tell Docker to use the new directory. Open or create thedaemon.json
file.sudo nano /etc/docker/daemon.json
We should add or change the following content:
{ "data-root": "/path/to/new/docker" }
Restart Docker Service:
After we save the changes, we can restart the Docker service to apply the new settings.sudo systemctl start docker
Verify the Changes:
We can check if Docker is using the new directory by running:docker info | grep "Docker Root Dir"
By following these steps, we can change the Docker image installation directory on Linux systems. For more details on Docker setup, we can check the article on How to Install Docker on Different Operating Systems.
Changing the Docker Image Installation Directory on Windows Systems
We can change the Docker image installation directory on Windows systems by modifying the Docker daemon configuration. Here is how we can do it:
Stop Docker Desktop: First, we need to make sure that Docker Desktop is not running before we change anything.
Edit Configuration File: Next, we open the Docker configuration file located at
C:\ProgramData\Docker\config\daemon.json
. If we do not find this file, we can create it.Add or Modify Storage Path: Now, we add or change the
data-root
property to set the new image installation directory. For example, if we want to set the directory toD:\DockerImages
, our configuration will look like this:{ "data-root": "D:\\DockerImages" }
Restart Docker Desktop: After we save our changes to the
daemon.json
file, we should restart Docker Desktop so the changes can take effect.Verify Configuration: We can check if the new installation directory is working by running this command in the command prompt:
docker info | find "Docker Root Dir"
This command will show the current Docker image installation directory. This way, we can confirm that our changes were successful.
By following these steps, we can easily change the Docker image installation directory on our Windows system. This helps us keep our Docker resources organized and managed well. For more information on Docker, we can read What is Docker and Why Should You Use It?.
Frequently Asked Questions
1. How can we change the Docker image installation directory on Linux?
To change the Docker image installation directory on Linux, we need
to set up the Docker daemon. First, we edit the Docker configuration
file. This file is usually found at
/etc/docker/daemon.json
. We can set a new directory by
adding the "data-root"
option. After we make these changes,
we restart the Docker service with
sudo systemctl restart docker
so the changes work.
2. Is it possible to change the Docker image installation directory on Windows?
Yes, we can change the Docker image installation directory on Windows. We need to change the Docker Desktop settings. First, we open Docker Desktop. Then we go to the “Settings” menu and click on the “Resources” tab. Under “File Sharing,” we can set a new place for our Docker images. After that, we restart Docker Desktop so the changes work.
3. What happens to existing Docker images when we change the installation directory?
When we change the Docker image installation directory, the old
images stay in the old directory unless we move them ourselves. It is
good to back up our images before we make changes. We can use commands
like docker save
to export our images. Then we can use
docker load
to import them to the new directory after we
change the Docker image installation path.
4. Can we have multiple Docker image directories?
Yes, we can set up Docker to use more than one directory for images, but it is not easy. Docker does not allow multiple data roots by itself. But we can use symbolic links or bind mounts to link other directories to the main Docker image installation directory. This way, we can manage images across different storage places easily.
5. Where are Docker images stored after installation?
By default, Docker images are in the /var/lib/docker
directory on Linux systems. On Windows, images are usually in the Docker
Desktop application data directory. If we change the Docker image
installation directory using the settings we talked about, the new path
will be where all images and containers are stored. For more info about
Docker image storage, we can check out this
article about Docker images and how they work.