3

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

Mirco Lcl
  • 373
  • 7
  • 19
  • "Why do you want to move it from one server to the other?" - The answer to this question would help me answer your query better. What's your end goal? – 7_R3X Dec 05 '19 at 10:26
  • Similar question [How to move Docker containers between different hosts?](https://stackoverflow.com/q/28734086/8482479) – b0gusb Dec 05 '19 at 10:30
  • Best practice would be the thing you did that works, `docker push` your images to a registry, copy the `docker-compose.yml` file to the other system, and run `docker-compose up` there. Don't worry about the specific containers as entities, and avoid `export` or `save` operations. – David Maze Dec 05 '19 at 11:15
  • @7_R3X mostly.. learning purposes – Mirco Lcl Dec 05 '19 at 11:53
  • @b0gusb I know that one. Tried exactly every solutions included but I didn't get the port configuration to preserve. – Mirco Lcl Dec 05 '19 at 11:54
  • @DavidMaze Thanks for your answer! I'll try as you suggested. – Mirco Lcl Dec 05 '19 at 11:54

1 Answers1

3

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

  • Thank you a lot for your answer. Everything worked flawlessy ( apart from the POSTGRE database, but i'll open a different question for this one since seems like there could be a different procedure!) – Mirco Lcl Dec 16 '19 at 13:46