动态改变码头容积 [英] Dynamically change docker volume
问题描述
基本上我有一个需要频繁重建的容器,而且很容易变化的容器。第二个容器需要第一个文件夹。
Basically I have one container that needs frequent rebuilds, and one that quite stable and changes very rarely. Second container needs folder from the first one.
有没有办法完成以下任务使用卷?
It there any way to accomplish following task using volumes?
创建容器卷:
# docker run -d -v /test-vol --name one ubuntu:14.04 cat
创建基于第一个容器的卷的第二个容器:
Creating second container with volume based on first container:
# docker run -d --volumes-from one --name two ubuntu:14.04 cat
现在我停止第一个容器,构建它的新版本。
Now I'm stopping first container, building it's new version.
这里的问题是:我需要一些魔法来启动它,以便第二个容器开始看到新版本volume / test-vol。
And here question goes: I need some sort of magic to start it in such way that the second container start to see the new version of volume /test-vol.
从码头检查角度来看,有
From docker inspect perspective there is
"VolumesFrom": [
"one"
]
所以我想可能我可以创建同名的新容器,但是我看到
so I thought may be I can create new container with the same name, but then I saw
"Volumes": {
"/test-vol": "/var/lib/docker/vfs/dir/[id]"
},
明确链接到旧卷。
推荐答案
最简单的解决方案是将第三个容器一个数据卷容器可以是:
The easiest solution would be to dedicate a third container as a data volume container which could then be:
- 由第一个为每次重建安装
- 第二个
数据卷容器可以由其他几个容器装载。
A data volume container can be mounted by several other containers.
这篇关于动态改变码头容积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!