0

I am using Docker 18.09 and I am trying to build some images for my work. The problem is that the images are always inside the root directory, precisely the /var/lib/docker/overlay2 are in /var/docker/. As there isn't enough space in my root directory, so I want to change this default directory to my other disk but none of the solutions I have looked upon the internet have worked for me.

I have gone through these already but none of them are working:

https://forums.docker.com/t/how-do-i-change-the-docker-image-installation-directory/1169

https://medium.com/@ibrahimgunduz34/how-to-change-docker-data-folder-configuration-33d372669056

How to change the docker image installation directory?

HimalayanCoder
  • 9,123
  • 6
  • 53
  • 59
  • Possible duplicate of [How to change the docker image installation directory?](https://stackoverflow.com/questions/24309526/how-to-change-the-docker-image-installation-directory) – David Maze Jul 10 '19 at 09:42

2 Answers2

1

The default directory to store docker related data (containers, images and so on) is /var/lib/docker.

To override this default location use -g option.

While starting docker deamon use -g option.

dockerd -g /mnt/path/to/docker/dir

In your case, the best option is to attach some external storage to machine at some mountpoint. And mention that mountpoint in -g option.

Hope this helps.

Update:

-g option is deprecated. Use --data-root option. Check this.

mchawre
  • 8,771
  • 3
  • 28
  • 54
0

I used the following technique when i too ran into this problem and using a different filesystem which had a larger size was the only available option left.

  1. Stop the docker service. sudo systemctl stop docker.service

  2. Edit the docker.service file to include the new directory in the ExecStart line as below. ExecStart=/usr/bin/dockerd -g /u01/docker -H fd:// --containerd=/run/containerd/containerd.sock

Reload daemon sudo systemctl daemon reload

Restart docker sudo systemctl start docker.service

Note: the docker.service file path is shown when you ran the systemctl stop docker.service

A much simpler and straightforward way out for this problem is to simply create a symbolic link to the new path once you move the existing folder like below.

sudo systemctl stop docker.service

sudo mv /var/lib/docker/ /

sudo ln -s / /var/lib/docker

sudo systemctl start docker.service