提交已装入卷的内容 [英] Commit content of mounted volumes as well
问题描述
我正在运行一个jenkins容器,并希望在容器提交中隔离其配置。唯一的问题是,码头工人不会提交已装载卷的更改-所以我必须卸载它们。
I have a jenkins container running and would like to have it's configuration isolated in a container commit. Only problem is that there docker won't commit changes of mounted volumes - so I have to unmount them.
有没有办法让码头工人装载卷, 提交对目录的更改?
Is there a way to let docker mount volumes and commit changes of the directories?
我了解了有关卷绑定的 readonly 选项。
I read about the readonly option for volume bindings. Might that help?
推荐答案
不幸的是,此功能不可用。已经提出过很多次,但开发人员并未接受。主要原因是可移植性。卷不应该是图像的一部分,而是存储在图像之外。
Unfortunately, this feature is not available. It has been proposed many times but not accepted by the developers. The main reason is portability; volumes are not supposed to be part of the image, and are stored outside the image.
不过,您仍然可以间接实现相同的目的。
You can still however achieve the same thing indirectly.
- 使用
docker commit
命令提交容器。 -
启动一个新的虚拟容器,该容器使用您要备份的容器中的卷。
- Commit you container using the
docker commit
command. Start a new dummy container that uses the volume from the container that you are trying to backup.
docker run -volumes-from< container -name> --name backup -it ubuntu bash
在容器中,一旦tar挂载了卷所在的文件夹。
Once inside the container, tar the folder where the volume is mounted.
使用
docker cp backup:volume.tar <将卷tar从虚拟容器复制到主机。 / p>
docker cp backup: volume.tar
现在您有多种选择:
-
使用Dockerfile创建一个新映像:
Create a new image using Dockerfile:
FROM commited-container-image
COPY volume.tar。
RUN tar -xf volume.tar -C到卷安装点的路径& \
rm -f volume.tar
或解压缩卷备份并将其作为绑定安装安装到根据容器提交映像创建的新容器上
Or untar the volume backup and mount it as a bind mount on the new container created from the container-commit image
这篇关于提交已装入卷的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!