Docker EXPOSE是否会新建一个层? [英] Does Docker EXPOSE make a new layer?
问题描述
我一直在创建docker文件并阅读文档,我想知道这个问题:是否在 Dockerfile中添加
添加图层? (如果可以,为什么我会关心它/将它放在文件中的位置也有关系吗?) EXPOSE
命令
I have been playing around with creating docker files and reading the documentation and I was wondering this question: Does adding an EXPOSE
command to my Dockerfile
add a layer? (and if it does why would I care/ does it matter where it is placed inside the file?)
在文档。
我理解 RUN
, COPY
和 ADD
创建图层是因为它们会更改文件系统,但暴露只是将元数据添加到了容器中,更改是否会生成一个层?
I understand RUN
, COPY
and ADD
create layers because they change the file system, but expose simply adds metadata to the container, does it change generates a layer?
推荐答案
我意识到自己可以对此进行测试。而且我发现添加EXPOSE不会添加新的文件系统层,但确实会添加一个层,这与为缓存层制作docker文件的顺序无关紧要。
I realised i could test this myself. and I've found that adding EXPOSE does not add a new file system layer, but it does add a layer none the less, also it does matter which order you make your docker files for your cache layers.
基本上:每个命令都会创建一个新层,每个更改文件系统的命令都会创建一个文件系统层。
basically: every command creates a new layer, every command that changes the file system creates a filesystem layer.
FROM ...
EXPOSE 80
COPY smthing .
不同于:
FROM ...
COPY smthing .
EXPOSE 80
多次执行(例如在开发环境中执行)。
When executed multiple times (say in a development environment).
在第一个示例中, EXPOSE
命令被缓存,即使 smthing也不执行
文件更改。如果something文件发生更改, docker build
将仅重新执行此命令(其余内容将从缓存中获取。)
in the first example the EXPOSE
command is cached and is not executed even if the smthing
file changes. If the something file changes, docker build
will only re-executed this command (rest is taken from cache).
在第二个示例中。如果 smthing
文件更改,EXPOSE命令也将被重建。 (因为复制命令之后的所有内容均无效,并在 docker build
上重新执行)。
In the second example. if the smthing
file changes, the EXPOSE command will also be rebuild. (since everything after the copy command is invalidated and re executed on docker build
).
我是否要更改EXPOSE
Would i change the EXPOSE port the first case would have to re-execute the copy command, where the second example wouldn't.
但是两者都将导致完全相同的最终结果文件系统
But both would lead to the exact same end result file-system layer wise.
docker inspect imageName #shows the file system layer
docker history imageName #shows all the layers
这篇关于Docker EXPOSE是否会新建一个层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!