dvaini
dvaini

Reputation: 331

How do I move a docker container's image to a persistent disk?

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?

Upvotes: 31

Views: 22539

Answers (4)

Ken A.
Ken A.

Reputation: 311

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.

Upvotes: 31

jcoffland
jcoffland

Reputation: 5430

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.

Upvotes: 27

ctrlplusb
ctrlplusb

Reputation: 13147

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.

Upvotes: 5

creack
creack

Reputation: 121742

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.

Upvotes: 17

Related Questions