7

I update my kernel of Debian from 3.x to 4.x.
Docker storage become overlay2.

ls /var/lib/docker/ 
containers  image  network  overlay2  plugins  swarm  tmp  trust  volumes

old directory structure is

aufs  containers  graph  image  init  linkgraph.db  network  plugins  repositories-aufs  swarm  tmp  tmp-old  trust  volumes

My images is in aufs directory, I can not start docker service with old directory. how can I move my images to overlay2?

Sword
  • 159
  • 1
  • 3
  • 10
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Jun 25 '17 at 21:59
  • Get it. Thank you. – Sword Jun 28 '17 at 10:54

3 Answers3

9
  1. Identify the images to save and restore after migrating from aufs to overlayfs2.

  2. Export all the images to be migrated to overlayfs into one archive - this is faster and efficient

    sudo docker save $IMAGES -o /data/save.tar

    Here IMAGES is a variable containing the image names

  3. Create /etc/docker/daemon.json with following contents:

    {
      "storage-driver": "overlay2"
    }
    

    [ Refer to https://stackoverflow.com/questions/42245288/add-new-element-to-existing-json-array-with-jq/57537190#57537190 for updating it using jq ]

  4. Take the backup of the directory where docker images are stored and delete the directory

    mv /var/lib/docker/images /var/lib/docker.aufs.images

  5. systemctl daemon-reload

  6. systemctl restart docker

  7. docker load < save.tar

fuenfundachtzig
  • 7,952
  • 13
  • 62
  • 87
pr-pal
  • 3,248
  • 26
  • 18
  • 1
    Should the command really be `mv /var/lib/docker /var/lib/docker.aufs.images` ? Is it not `mv /var/lib/docker/images /var/lib/docker.aufs.images` ? And for consistency, all commands should be executed with `sudo ...` ? Just asking – knb Sep 11 '20 at 15:42
  • What about volumes. *Those* are usually the actual precious data that cannot be recreated. – Jan Hudec May 18 '21 at 16:55
  • 2
    All my containers are now missing, i need to move more than images! – Brunis Sep 14 '21 at 05:56
  • There is this french page, which provides some scripts to migrate all images: https://www.sylvaincoudeville.fr/2019/12/docker-migrer-le-stockage-aufs-vers-overlay2/ I experienced that all my previous containers are missing after migration, like @Brunis noticed earlier. As I did not found a solution to this, you'll need proper compose configs (or so) for your containers, in order to restart them after migrating the images. – Roy Sep 27 '21 at 12:14
0

based on fuenfundachtzig and pr-pal post

  1. Check your current storage -driver

    sudo docker info | grep -i storage

    return Storage Driver: aufs

  2. Backup all docker stuff

    sudo systemctl stop docker

    sudo cp -au /var/lib/docker /var/lib/docker.bk

    sudo systemctl start docker

  3. Identify the images to save and restore after migrating from aufs to overlayfs2

    mkdir -p /data

    sudo sh -c 'docker images > /data/list_images.txt'

  4. Export all the images to be migrated to overlayfs into one archive - this is faster and efficient

    Here IMAGES is a variable containing the (uniq) image names

    IMAGES=$(sudo docker images | sed '1d' | awk '{print $3}' | uniq)

    for c in $IMAGES; do echo $c; sudo docker save -o /data/$c.tar $c ; done

  5. sudo systemctl stop docker

  6. Change Storage drive from aufs to overlayfs2

    Create or modify /etc/docker/daemon.json with following contents:

    if the file is already there, add line as following

    {
        "storage-driver": "overlay2"
    }
    

    if the file is empty, you can go with

    sudo sh -c " echo '{ \"storage-driver\" : \"overlay2\" }' > /etc/docker/daemon.json "
    
  7. systemctl daemon-reload

  8. sudo systemctl restart docker

  9. Restore docker images

    IMAGES=$( cat /data/list_images.txt | sed '1d' | awk '{print $3}' | uniq)
    for c in $IMAGES; do sudo docker load -i /data/$c.tar; done
    
  10. Check your new storage driver

    sudo docker info | grep -i storage

    return Storage Driver: overlay2

  11. Remove backup of docker directory

    sudo rm -rf /var/lib/docker.bk

c-tools
  • 83
  • 7
-1

You can actually set the storage driver to use. It is possible that the upgrade has changed a default file or configuration to overlay2. You may be able to change it back to aufs. The documentation on this is at https://docs.docker.com/engine/userguide/storagedriver/selectadriver/#check-and-set-your-current-storage-driver.

Also, depending on the Docker version you are running, the setting could be in /etc/default/docker instead of /etc/docker/daemon.json.

Andy Shinn
  • 26,561
  • 8
  • 75
  • 93