Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting a container created with docker-compose

I have a series of containers created with docker-compose. Some of these containers communicate between each other with some rules defined in the docker-compose.yml file.

I need to move those containers from a serverA to serverB (same OS) but i'm having issues in understanding how this works.

I tried both with the export and the save methods following tutorials i've found on the web but I was not able to get the port configurations and networking rules after the export - import or save - load operations (there's a chance I didn't really get how they work...)

The only way I've found to succesfully do this is to copy the whole docker-compose folder and run docker-compose up in serverB.

The question:

Is there a way to preserve the whole configuration of the containers and move them from a server to another using the export or save function?

Thank you for any help you can provide

like image 641
Mirco Lcl Avatar asked Jul 13 '26 02:07

Mirco Lcl


1 Answers

2 scenarios:

Copy via ssh

$ sudo docker save  myImage:tag | ssh user@IPhost:/remote/dir docker load -

Copy via scp

#Host A
$ docker save Image > myImage.tar
$ scp myImage.tar IPhostB:/tmp/myImage.tar
# Host B
$ docker load -i /tmp/myImage.tar

And then you need to copy the docker-compose.yml to the host B too.

The containers only have the original build's own configurations, but they don't save the environment that we generate with the file docker-compose.yml

Bye

like image 124
Pablo Anaquín Avatar answered Jul 14 '26 17:07

Pablo Anaquín



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!