在主机之间移动docker-compose容器集 [英] Moving docker-compose containersets around between hosts
问题描述
我想获取由3个docker映像组成并由docker-compose管理的应用程序堆栈,并将其全部从开发机器移至生产机器。我知道有几种方法可以直接使用docker:
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:
- 将图像推送到注册表并将其从生产环境撤回
- 从开发中保存docker,然后将docker加载到生产中
- 在生产中重建映像(宁愿保持对生产的依赖性,所以不是一个好的选择。)
我目前倾向于先保存docker然后再加载docker,但我想知道是否有办法做到这一点docker-compose管理的整套容器?
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?
预先感谢
推荐答案
撰写中没有功能保存构建在Compose文件中的图像,这是docker客户端的工作(如您使用 docker save
和 docker load
)。幸运的是,使用bash很简单:
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
远程注册表选项也许是一种更生产级的方法。左右移动一堆图像可能会非常慢,但是YMMV。
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.
这篇关于在主机之间移动docker-compose容器集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!