Docker – Move docker data (images and containers) to separate drive with different FS

docker

I am planning to move docker data (images and containers) to separate drive as they require many space.

As I know I can move /var/lib/docker to separate drive and create soft link to it. But I have read that BTRFS is a best file system option for docker.

But I suspect it is not enough to format external drive to BTRFS and move existing folder to it. As I see the content of this folder depends on the using file system.

How can I move (recreate) docker folder (images and containers) on the external drive with different file system correctly?

Best Answer

As you stated simply moving or copying the docker images/containers from the default AUFS to BTRFS formatted drive is not going to work. So as a first step, you can commit all your containers as images and use docker save commands to save the images as .tar files and then once you have prepped docker to use btrfs, you run docker load to load the images into the new storage driver.

The steps would be roughly as follows - this is what i did in my Ubuntu 14.10 box -

  • Save your images
    docker save IMAGEID > /tmp/redis.tar
  • Prep btrfs
 mkfs.btrfs /dev/sdb
 mkdir /var/lib/docker-btrfs
 mount /dev/sdb /var/lib/docker-btrfs/
  • Stop docker and set docker to utilize btrfs and run it.
service docker stop
docker -d -s btrfs  --graph="/var/lib/docker-btrfs"  -H unix:///var/run/docker.sock

The above step can also be accomplished by modifying /etc/default/docker.

  • Load the images.
docker load --input /tmp/redis.tar

You should be able to see the images and run containers from here. For containers, you can also try export and import methods, i have never tried that one though.

Related Topic