Docker Community Forums

Share and learn in the Docker community.

How to change /var/lib/docker directory with Overlay2

Hi, as in the title, i’m trying to know how change the /var/lib/docker default installation folder with another in a different partition. This because i’ve no enough space in root partition but i still need of all installed containers. I searched on the web for this question before ask it here. Who can help me?

Good year to all. :slight_smile:

stop the docker deamon
make a link to another folder for the ‘docker’ path (/var/lib/{symlink})
start the docker daemon

2 Likes

@sdetweil thanks for reply… more simple than i was think :slight_smile:
but before links the docker folder, i’ve to move existents contents into the new directory?

yes

  • make the new folder on the other volume,
  • stop the docker daemon,
  • move everything,
  • make a symbolic link,
  • start docker daemon…

@sdetweil thanks! it works!

Good year. :wink:

Hi, I did this but I get an error while trying to build an image from Dockerfile saying:

OCI runtime create failed: /var/lib/docker/overlay2/6b43fa390506232a0d0895db436eebaf717d630a05d40b464f24673fdbd273c9/merged is not an absolute path or is a symlink: unknown

Could this be related to creating the symlink? I remember it working fine before creating the symlink.

1 Like

Did u copy everything from the original /var/lib to the new location with the same privileges?

I am actually seeing this same exact issue but in a slightly different scenario. Instead of having the entire /var/lib/docker directory symlinked, I only symlinked /var/lib/docker/overlay2 to have it mapped to a separate mount so as to minimize space consumption on my root filesystem.

So, yeah, definitely related to being symlinked. I’m doing more research but thought I’d pop in to this thread to mention this.

I found the same. You must move the entire /var/lib/docker directory and symlink it, not just a subdirectory.

How about doing it properly? Edit the file /etc/docker/daemon.json and add or modfy the “data-root” entry. If you configuration is empty, the file will look like this:

{
“data-root”: “/new/data/root/path”
}

Restart the docker daemon!

source:

Warning: all images, containers and such will be unavailable, unless you move the data from /var/lib/docker to the new location. If the new location is formated with a different filesystem, it might happen that a diferent storage driver is used, which will NOT be able to read the data written by the previous storage driver.

5 Likes

@meyay: Thank you. This info saved my day.