How to move Docker image storage to a data volume
The docker image data is stored under /var/lib/docker
directory in the docker host for UNIX systems, which does not have a substitution command or argument to switch the default path. However, you can definitely do that by making some changes to the docker’s service file directly or via a symbolic link.
Here are steps you can follow:
1. Stop Docker:
On a system that uses:
- Systemd run:
sudo systemctl stop docker
- Upstart run:
sudo service docker stop
- SysV init run:
/etc/init.d/docker stop
2. First, back up your existing Docker directory (/var/lib/docker
), to prevent any data loss from misoperation:
3. Move Docker image data:
Move the Docker image data to your specific path - e.g /data
:
4. Create a symbolic link:
5. Start Docker:
On a system that uses:
- Systemd run:
sudo systemctl start docker
- Upstart run:
sudo service docker start
- SysV init run:
/etc/init.d/docker start
Now, Docker should use /data/docker
directory as data volume for local image/containers build.
Please note: The process described above includes instructions that require high privileges and therefore, consider potential risks before execution.