同步Docker映像 [英] Syncing docker images
问题描述
我有2台运行docker的机器(单独的主机),并且我在两台机器上使用相同的映像。如何使两个图像保持同步。例如。假设我对其中一台主机中的映像进行了更改,并且希望这些更改也能反映在另一台主机中。我可以提交映像并将映像复制到其他主机。还有其他有效的方法吗?
I have 2 machines(separate hosts) running docker and I am using the same image on both the machines. How do I keep both the images in sync. For eg. suppose I make changes to the image in one of the hosts and want the changes to reflect in the other host as well. I can commit the image and copy the image over to the other host. Is there any other efficient way of doing this??
推荐答案
我可以想到的一些方法:
Some ways I can think of:
此处的工作流程是:
- 主机A:
docker commit
,docker push
- 主机B:
docker pull
- HOST A:
docker commit
,docker push
- HOST B:
docker pull
此处的工作流程为:
- 主机A:
docker save
- 主机B:
docker load
- HOST A:
docker save
- HOST B:
docker load
此处的工作流程为:
- 每次提供更改代码并想要创建一个
Dockerfile
以及所需的代码/文件 - 发布后,使用
docker build
创建新映像。 - 从要进行更新的主机中,您将拥有以获得更新的源代码(可能使用诸如Git之类的版本控制软件),然后
docker build
图片
- provide a
Dockerfile
together with your code / files required - everytime your code has changed and you want to make a release, use
docker build
to create a new image. - from the hosts that you want to take the update, you will have to get the updated source code (maybe by using a version control software like Git), and then
docker build
the image
您可以在此处观看视频: docker.com/use-cases/cicd
you can see a video here: docker.com/use-cases/cicd
请记住容器
被视为短暂。这意味着更新另一个主机中的图像
将需要:
Keep in mind that containers
are considered to be ephemeral. This means that updating an image
inside another host will then require:
- 到
停止
并删除
任何旧容器(使用过时的图像运行) - 到
运行
运行一个新的(具有更新的图像)
- to
stop
andremove
any old container (running with the outdated image) - to
run
a new one (with the updated image)
我引用自:编写Dockerfile的最佳做法
一般准则和建议
容器应为临时容器
由Dockerfile定义的映像生成的容器应尽可能为临时容器。 临时是指可以将其停止并销毁,并且可以使用最少的设置和配置来构建和放置新的。
这篇关于同步Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!