派生映像时会继承哪些Dockerfile指令? [英] Which Dockerfile instructions are inherited in deriving images?

查看:141
本文介绍了派生映像时会继承哪些Dockerfile指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个Dockerfile,分别用于创建带有相应标签的映像:

Let's say I have two Dockerfiles that I use to create images with respective tags:

Dockerfile.A:

FROM some-image

...
EXPOSE 9000

ENTRYPOINT ["some-script.sh"]

Dockerfile.B:

FROM A 

...

运行映像B时,容器是否还会公开我在 Dockerfile.A 中定义的端口,并运行在那里定义的入口点脚本?

When I run the image B, does the container also expose the port that I defined in Dockerfile.A, and run the entrypoint script defined there?

更一般而言,说明都是从基本Dockerfile继承的,除了文件系统层之外?

More generally, which instructions are inherited from base Dockerfiles, apart from the file system layers?

推荐答案

这些指令与系统文件一起从基本映像继承.

These instruction are inherited from the base image along with system files.

曝光

如果基本映像在Dockerfile中提到了这些 EXPOSE 8080 9090 端口,则扩展Dockerfile不需要公开这些端口.但是 expose和publish 之间是有区别的.

If the base image mentioned these EXPOSE 8080 9090 ports in Dockerfile, then the extend Dockerfile do not to need to expose these port. But there is a difference between exposing and publish.

ENV

如果基本映像具有某些ENV,例如 test-a = abc ,则扩展映像将具有这些ENV.

If the base image has some ENV like test-a=abc then extended image will have these ENVs.

WorkingDir

如果基本映像已设置"WorkingDir":"/root" ,则扩展的iamge将具有有效的目录/root

If the base image have set "WorkingDir": "/root", then extended iamge will have working direcotry /root

维护师

MAINTAINER adiii 扩展图像如果没有覆盖,将具有相同的作者.

MAINTAINER adiii extended image will have the same author if not overide.

标签

扩展图像将与基础图像具有相同的标签

The extended image will have the same label as the base image

在建

设计为通过扩展映像运行.

Designed to run by extended image.

ENTRYPOINT

与基本映像中的入口点相同,除非您将其覆盖.

Same entrypoint as in the base image, unless you overwrite it.

CMD

只要不覆盖入口点指令,扩展映像与基本映像的CMD相同,请参见下文.

The extended image has the same CMD as the base image, as long as you do not overwrite the entrypoint instruction, see below.

您可以尝试.

Dockerfile A

Dockerfile A

FROM node:8.16
MAINTAINER adiii
LABEL key=test
EXPOSE 8080 9090
ENV test-a=abc
WORKDIR /root
ENTRYPOINT /root
CMD ["npm", "run", "start"]

现在构建docker镜像B

Now build docker image B

Dockerfile B

Dockerfile B

FROM a

docker build -t b.使用b检查代码镜像 docker inspect b:latest ,您将看到从基本镜像继承的上述指令,因为Dockerfile B没有覆盖入口点指令.

docker build -t b . Inspect the image b docker inspect b:latest you will see the above instruction iherited from the base image, because Dockerfile B did not overwrite the entrypoint instruction.

如果扩展映像覆盖了入口点,则

If the extended image overwrites the entrypoint, the documentation says CMD will reset to an empty value and must be redefined if wanted.

这篇关于派生映像时会继承哪些Dockerfile指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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