How to change the docker image installation directory?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Changing the installation directory of Docker images is a task that may arise from various needs, such as enhancing performance, improving data organization, or managing storage limitations on default file systems. Docker, by default, stores data—such as images, containers, and volumes—under the /var/lib/docker directory path. However, you can customize this setting to a different directory. This article explains how to change the Docker image installation directory.
Understanding Docker Storage
Before altering Docker's storage directory, it's important to understand how Docker stores its data. Below is a brief overview:
- Images: Docker images are stored on disk in the graph driver, which can be found under
/var/lib/docker/<driver>/. - Containers: Each container has its own dedicated directory under
/var/lib/docker/containers/. - Volumes: When created, volumes reside under
/var/lib/docker/volumes/. - Configuration: The server's state and configuration settings exist in
/var/lib/docker.
Key Points Summary
| Component | Default Location | Storage Description |
| Images | /var/lib/docker/<driver>/ | Stores Docker images using the graph storage driver |
| Containers | /var/lib/docker/containers/ | Contains running and stopped containers' data |
| Volumes | /var/lib/docker/volumes/ | Persistent storage that's independent of containers |
| Configuration | /var/lib/docker/ | Docker daemon configuration and state files |
Preparation Steps
- Ensure Docker is not running:
Execute command:
- Backup Docker Data:
To prevent data loss, back up your Docker data. You can copy the entire/var/lib/dockerdirectory to another location:
- Decide on a New Directory:
Choose a location with adequate space available for storing Docker data (e.g., a separate disk or partition).
Changing Docker Directory
To change Docker’s default storage directory, follow these steps:
Step 1: Create a New Docker Directory
Make a new directory where you want Docker images to reside. Ensure Docker has permissions to write to this directory.
Step 2: Modify the Docker Daemon Configuration
Depending on your system, configure the Docker daemon by modifying the settings used to launch Docker. On most Linux systems, Docker is managed by systemd.
- Edit Docker Daemon Configuration
Open or create the/etc/docker/daemon.jsonfile:
Ensure this file is set to change the data root option to your new directory:
- Configure Systemd
If thedaemon.jsonfile isn't available, or if additional configurations are needed, you can use asystemdoverride file:
Create an override.conf file:
Step 3: Restart Docker Service
- Reload the systemd configurations and restart Docker:
- Verify the new configuration by checking where your Docker images are stored:
Look for the Docker Root Dir entry to confirm the change.
Step 4: Verify Docker Functionality
Ensure Docker images work as expected by pulling a test image:
This command confirms whether Docker is operating correctly under the new configuration.
Final Considerations
Changing Docker's storage directory is beneficial for troubleshooting storage space limitations and optimizing environment variable configurations. However, exercise caution when modifying these settings. Always back up your Docker data before making changes and verify the adjustments with functional checks.
Possible Caveats
- Verify the file permissions for the new directory to avoid permission-related issues.
- Consider the filesystem type of your new directory as some filesystems may not be compatible with Docker's overlay storage drivers.
- Make sure there is adequate disk space available to accommodate future growth of Docker images and containers.
With this guidance, you can efficiently change Docker's image installation directory to match your storage and organizational needs.

