how to import export docker compose?

11,809

Solution 1

If you want to move the running container instance then I would recommend you to run the below command

$ docker ps
 CONTAINER ID    IMAGE             COMMAND       CREATED       STATUS       NAMES
 c3f279d17e0a   ubuntu:12.04      /bin/bash      7 days ago    Up 25 hours desperate_dubinsky
 197387f1b436   ubuntu:12.04      /bin/bash      7 days ago    Up 25 hours focused_hamilton

$ docker commit c3f279d17e0a  svendowideit/testimage:version3

This would create the image on the host machine and then run the below command to save the image as tar file to upload it into another host.

$ docker save -o testimage.tar svendowideit/testimage:version3

On scp the tar image to another host run the below command to extract the tar and save it as docker images.

 $ docker images
 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

 $ docker load --input testimage.tar
 Loaded image: svendowideit/testimage:version3

 $ docker images
 REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
 svendowideit/testimage version3            769b9341d937        7 weeks ago         2.489 MB

Now you can make use of docker run command to bring up the docker instance of the saved images.

Solution 2

A running container can be exported into a tar archive which can be copied to a different machine and them be imported back.

On the machine where the container is running, do the following:

docker export --output "A.tar" <container-A> 

Next copy the generated archive A.tar to your machine, and import it:

docker import A.tar <container-A-image>

This will create an image on your machine which can be then started using docker run ...

Share:
11,809
ivanprakasa
Author by

ivanprakasa

Indonesian Web engineer based in Japan.

Updated on June 08, 2022

Comments

  • ivanprakasa
    ivanprakasa almost 2 years

    I am still new in docker and all container things. I have server with full access at 1.1.1.1 and I installed docker there. (without docker compose) In the other place my friend have server 2.2.2.2 and he installed docker and docker compose there.

    At 2.2.2.2 server, my friend build 3 container : container A (Git), container B(unknown), container C(unknown). I can access content of container A (Git) with browsers.

    My question is: can I import container A to my server in 1.1.1.1? I have user access to download Git, but what I want is to import the container, not Git (content inside the container). Any hint? what should I do? Or it is impossible to do if I don't have access to the command console?