How to move Docker containers between different hosts?

后端 未结 6 1067
借酒劲吻你
借酒劲吻你 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:44

    Use this script: https://github.com/ricardobranco777/docker-volumes.sh

    This does preserve data in volumes.

    Example usage:

    # Stop the container   
    docker stop $CONTAINER
    
    # Create a new image   
    docker commit $CONTAINER $CONTAINER
    
    # Save image
    docker save -o $CONTAINER.tar $CONTAINER
    
    # Save the volumes (use ".tar.gz" if you want compression)
    docker-volumes.sh $CONTAINER save $CONTAINER-volumes.tar
    
    # Copy image and volumes to another host
    scp $CONTAINER.tar $CONTAINER-volumes.tar $USER@$HOST:
    
    # On the other host:
    docker load -i $CONTAINER.tar
    docker create --name $CONTAINER [] $CONTAINER
    
    # Load the volumes
    docker-volumes.sh $CONTAINER load $CONTAINER-volumes.tar
    
    # Start container
    docker start $CONTAINER
    

提交回复
热议问题