Moving docker-compose containersets around between hosts

廉价感情. 提交于 2019-12-18 20:04:29

问题


I would like to take my application stack, consisting of 3 docker images and managed by docker-compose, and move it in its entirety from my development machine onto a production machine. I know of a few ways to do this with straight up docker:

  • Push the images to the registry and pull them back out from production
  • docker save from development and then docker load on production
  • rebuild the images on production (would rather keep dependencies down on production, so not a good option.)

I'm currently leaning towards doing docker save and then docker load, but am wondering if there's a way to do this with the whole set of containers that docker-compose manages?

Thanks in advance


回答1:


There is no functionality in Compose to save the images built in a Compose file, it's the job of the docker client (as you stated with docker save and docker load). Fortunately it's straightforward with bash:

images=(web cache db)
for image in images
do
    docker save ${image} > ${image}.tar
    scp ${image}.tar $yourhost:
    ssh $yourhost docker load ${image}.tar
done

The remote registry option is perhaps a more "production grade" approach. Moving a bunch of images around is likely to be pretty slow, but YMMV.



来源:https://stackoverflow.com/questions/35024216/moving-docker-compose-containersets-around-between-hosts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!