How to move Docker containers between different hosts?

I cannot find a way to move dockers running containers from one host to another.

Is it possible to somehow send my containers to the repository, as we do for images? I currently do not use data volumes to store data associated with applications running inside containers. Therefore, some data is inside the containers that I want to save before changing the settings.

+79
docker containers docker-registry
Feb 26 '15 at 3:43 on
source share
6 answers

You cannot move a working docker container from one host to another.

You can commit the changes to your image container using docker commit , move the image to a new host, and then start the new container using docker run . This will save all the data created by your application inside the container.

Nb: It does not save data that is stored inside volumes; you need to move the data volumes manually to the new host.

+43
Feb 26 '15 at 3:50
source share

Alternatively, if you do not want to send to the repository:

  1. Export container to tarball

     docker export <CONTAINER ID> > /home/export.tar 
  2. Move your tarball to a new car

  3. Import back

     cat /home/export.tar | docker import - some-name:latest 
+81
Feb 26 '15 at 20:07
source share

In the end, after many confusing guides and confusing tutorials, it worked for me that Docker, obviously, at the time of my writing on the look of overstated expectations , is:

  1. Save the docker image to the archive:
    docker save image_name > image_name.tar
  2. copy to another machine
  3. on another Docker machine, start the Docker download as follows:
    cat image_name.tar | docker load

Export and import, as suggested in other answers, do not export ports and variables that may be required for your container to work. And you may experience things like "Command not specified" , etc. .... when you try to download it to another computer.

Thus, the difference between saving and exporting is that the saving command saves the entire image with history and metadata, and the export command only exports the file structure (without history or metadata).

It goes without saying that if you already have these ports occupied by the docker hypervisor that you are importing through some other docker container, you will be in conflict and you will have to reconfigure the open ports.

+20
May 11 '18 at 22:17
source share

From the Docker documentation:

docker export does not export the contents of associated volumes with the container. If the volume is installed on top of an existing directory in the container, docker export will export the contents of the main directory, not the contents of the volume. refer to Backing up, restoring, or migrating data volumes in the user guide for examples on exporting data in a volume.

Other external tools: To move a container with its associated data volume, you can use Flocker https://clusterhq.com/flocker/introduction/

+16
Aug 08 '15 at 10:52
source share

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

This saves data in volumes.

Usage example:

 # 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 [<PREVIOUS CONTAINER OPTIONS>] $CONTAINER # Load the volumes docker-volumes.sh $CONTAINER load $CONTAINER-volumes.tar # Start container docker start $CONTAINER 
+3
Oct 30 '18 at 15:52
source share

I have tried many solutions for this, and this is what works for me:

1. save / save container in new image:

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

ps: "Our CONTAINER_NAME container has a mounted volume in" / var / home "" (you should check your container to indicate its path: # docker inspect CONTAINER_NAME)

  1. ++ save its volume: we will use the image of Ubuntu to do this.
    # Backup mkdir
    # docker run --rm - -v in fields - from CONTAINER_NAME -v $ {pwd} / backup: / backup ubuntu bash -c "cd / var / home && tar cvf / backup / volume_backup.tar."

Now that you look at $ {pwd} / backup, you will find our volume in tar format.
So far we have the image of conatainer 'IMAGE_NAME.tar' and its volume 'volume_backup.tar'.

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

+1
Jul 17 '19 at 17:01
source share



All Articles