22

We have noticed that our containers are taking up a lot of space, one of the reasons for this is the images.

We would like to move the images.

I know right now they are stored in /var/lib/docker/graph/<id>/layer

Is there a way to move these to another location/persistent disk?

user3666197
  • 1
  • 6
  • 43
  • 77
dvaini
  • 233
  • 1
  • 2
  • 5

4 Answers4

27

To move images to another drive or another server:

docker save image_name > image_name.tar

mv image_name.tar /somewhere/else/

Load it back into docker

docker load < image_name.tar 

Reference.

Pablo Bianchi
  • 1,039
  • 1
  • 15
  • 23
Ken A.
  • 271
  • 2
  • 3
14

You can always mount /var/lib/docker to a different disk. Otherwise, you can start the daemon with -g /path in order to tell docker to use a different directory for storage.

creack
  • 98,809
  • 12
  • 89
  • 71
9

Here's any easy way to move docker's data:

sudo service docker stop
sudo mv /var/lib/docker /a/new/location
sudo ln -s /a/new/location /var/lib/docker # Create a symbolic link
sudo service docker start

No need to change DOCKER_OPTS or use -g /path.

jcoffland
  • 4,677
  • 35
  • 40
4

Using the answer by @creack I did the following on my Ubuntu install to move my entire docker images/containers folder to a new location/disk. The great thing about doing this is that any new images that I install will then use the new disk location.

First stop the docker service:

sudo service docker stop

Then move the docker folder from the default location to your target location:

sudo mv /var/lib/docker /thenewlocation

Then edit the /etc/default/docker file, inserting/amending the following line which provides the new location as an argument for the docker service:

DOCKER_OPTS="-g /thenewlocation/docker"

Restart the docker service:

sudo service docker start

This worked 100% for me - all my images remained in tact.

Community
  • 1
  • 1
ctrlplusb
  • 11,352
  • 5
  • 48
  • 55