How to move Docker containers between different hosts?

后端 未结 6 1056
借酒劲吻你
借酒劲吻你 2020-12-04 06:01

I cannot find a way of moving docker running containers from one host to another.

Is there any way I can push my containers to repositories like we do for images ? C

6条回答
  •  遥遥无期
    2020-12-04 06:50

    I tried many solutions for this, and this is the one that worked for me :

    1.commit/save container to new image :

    1. ++ commit the container:
      # docker stop
      # docker commit CONTAINER_NAME
      # docker save --output IMAGE_NAME.tar IMAGE_NAME:TAG


    ps:"Our container CONTAINER_NAME has a mounted volume at '/var/home'" ( you have to inspect your container to specify its volume path : # docker inspect CONTAINER_NAME )

    1. ++ save its volume : we will use an ubuntu image to do the thing.
      # mkdir backup
      # docker run --rm --volumes-from CONTAINER_NAME -v ${pwd}/backup:/backup ubuntu bash -c “cd /var/home && tar cvf /backup/volume_backup.tar .”

    Now when you look at ${pwd}/backup , you will find our volume under tar format.
    Until now, we have our conatainer's image 'IMAGE_NAME.tar' and its volume 'volume_backup.tar'.

    Now you can , recreate the same old container on a new host.

提交回复
热议问题