Skip to content

Instantly share code, notes, and snippets.

@entelecheia
Last active February 24, 2024 20:17
Show Gist options
  • Save entelecheia/0d9f69f504abac2a585bf17489da9fb6 to your computer and use it in GitHub Desktop.
Save entelecheia/0d9f69f504abac2a585bf17489da9fb6 to your computer and use it in GitHub Desktop.
[Docker] How to move Docker image storage to a data volume

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:

cp -au /var/lib/docker /var/lib/docker.bk

3. Move Docker image data:

Move the Docker image data to your specific path - e.g /data:

mv /var/lib/docker /data

4. Create a symbolic link:

ln -s /data/docker /var/lib/docker

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment