ceradini
ceradini

Reputation: 475

Exporting a docker-compose container

I used docker-compose to create an app that is composed by three images. I would like to understand now how can I export this app with the all services included.

Just for clarification the containers and images are the following:

container ls -a
CONTAINER ID   IMAGE
82522c850e9c   docker-app_client
7c796b6629bb   docker-app_server
66c84b58da2b   mongo

docker images
docker-mice-tracking-app_server
docker-mice-tracking-app_client
mongo

I can start my application from the folder in which i build the docker images by typing docker-compose up.

How can I export this images and replicate the same behavior on a different machine?

Thank you.

Upvotes: 0

Views: 4064

Answers (3)

sky
sky

Reputation: 359

A quick tip, if you don't have access to the docker registry and need to migrate all the finished containers to another machine from your docker-compose.yml file, you can run a script like this:

grep -oP "container_name:\s+\K(.*)" docker-compose.yml | while read cn; do docker export "${cn}" > "${cn}.tar"; done

or

docker compose config | grep -oP "container_name:\s+\K(.*)" | while read cn; do docker export "${cn}" > "${cn}.tar"; done

if your container names have variables.

But, the docker export command does not export the contents of volumes associated with the container. If a volume is mounted on top of an existing directory in the container, docker export will export the contents of the underlying directory, not the contents of the volume. Read more.

Then copy and load these files:

for f in $(find . -type f -name '*.tar'); do docker load -i "${f}"; done

Upvotes: 1

abhishek phukan
abhishek phukan

Reputation: 791

Couple of ways here.

  1. Store all images in a docker registry. For this you need to tag and push the images. Once you have that done , copy over the compose file to the new machine and run the docker-compose up. Note that you will have to change the image name on your compose to reflect the images you had retagged in order to be able to pull them down.

  2. If you do not have access to a docker registry , you can save the docker images using a docker save command which will create a tar file of those images. Copy those tar files over to a new system and do a docker load to load them as images from the tar file. Once done , you can run the docker compose command to deploy them on the new system

Upvotes: 4

HNK
HNK

Reputation: 1

I think you can push your images onto a docker registry by using

docker push

Then from other machines, you pull the images and run it.

The documentation is here

Upvotes: 0

Related Questions