Docker音量绑定:基本图像与衍生图像 [英] Docker volume binding: Base image vs derivative image

查看:174
本文介绍了Docker音量绑定:基本图像与衍生图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来像运行中使用的任何卷绑定 -v )基本图像将不会保留在您提交的派生图像中,并且每次运行派生图像时,必须传递卷绑定选项。

It looks like any volume binding (-v) used when you run a base image will not be retained in the derived image that you commit, and the volume binding option has to be passed each time you run the derived image.

示例:

docker run -it -v /opt/hostappsdir:/apps ubuntu

容器(名为: john_doe )并提交到新的图像( local / test

make changes in the container (named: john_doe) and commit to a new image (local/test)

docker commit john_doe local/test

然后,这不会列出主机目录 / opt / hostappsdir

Then, this does not list the files in the host directory /opt/hostappsdir

docker run --rm local/test ls /apps

但这一个是

docker run --rm -v /opt/hostappsdir:/apps local/test ls /apps






有没有办法我可以避免每次传递卷绑定选项?


Is there any way I can avoid passing the volume binding option each time?

推荐答案

卷定义不是容器层的一部分,因此不会成为从容器创建图像时提交的图层的一部分。

Volumes are by definition not part of the layers of the container and thus will not be part of the layers you commit when creating a Image from the container.

如果你喜欢eg添加一些特定的配置,添加一些扩展,添加一些包,你应该总是从基本的图像派生出来,从不只是提交任意,而不是正式的更改。

If you like to e.g. add you specific configuration, add some extensions, add some packages, you should always derive from the base image, never just "commit" arbitrary, not formalised changes.

创建一个来自< baseimage>的

Create a Dockerfile with

from <baseimage>
COPY yourconfig /etc/somewhere
COPY yourasset /var/www

RUN sed ... \ // change some configuration
  && apt-get update && apt-get install curl // some packages

提示:我自己不喜欢提交将容器更改为图像 - 这是有风险的,每次都不会产生相同的结果,而不是形式化您实际改变的内容。由于您不了解您所做的一切 - 即使您已经写下来,您也会因为更新基础图像而更新您的图像,而且还要再次做出很多努力,再次。

Hint: I do myself not like the idea of "commiting changes a containers to an image" - that is risky, does not produce the same result every time and more over, does not formalise what you actually changed. You will have hard times .e.g updating your image due to updates of the base image, since you do not know, what you have done - and even if you have written it down, its a lot of effort to do that again, again and again.

这篇关于Docker音量绑定:基本图像与衍生图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆