Reputation: 217
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?
Upvotes: 9
Views: 22871
Reputation: 4880
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.
Upvotes: 10
Reputation: 51876
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 ...
Upvotes: 2
Reputation: 1137
No. If you would like to have had the image, which is used to run the container A(Git), then your friend has to push the Docker image to a Docker registry. This will give you the possibility to run the same Docker image as Docker container on your server. But not the data.
Docker images are by design immutable. Started Docker Images are called Docker Containers. Basically this Docker containers are completely deleted if you stop and remove them. If you have data you would like to persists, then you can use so called bind volumes
, for example.
You see, your question is very broad. And there are ways to achieve what you want, but I can only point you to some documentation to go further. Or you can join a local meetup, which would be the fastes way to come aboard.
https://www.slideshare.net/Docker/introduction-to-docker-2017
Upvotes: -1