- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我搜索过 site:stackoverflow.com dockerfile: ENV, RUN - layers or images
并已阅读 Does Docker EXPOSE make a new layer?和 What are Docker image "layers"? .
在阅读文档时 Best practices for writing Dockerfiles并试图理解这部分:
Each ENV line creates a new intermediate layer, just like RUN commands. This means that even if you unset the environment variable in a future layer, it still persists in this layer and its value can be dumped.
In older versions of Docker, it was important that you minimized the number of layers in your images to ensure they were performant. The following features were added to reduce this limitation:
Only the instructions RUN, COPY, ADD create layers. Other instructions create temporary intermediate images, and do not increase the size of the build.
ENV
未设置:
$ docker build -t alpine:envtest -<<HITHERE
> FROM alpine
> ENV ADMIN_USER="mark"
> RUN unset ADMIN_USER
> HITHERE
Sending build context to Docker daemon 3.072kB
Step 1/3 : FROM alpine
latest: Pulling from library/alpine
89d9c30c1d48: Already exists
Digest: sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a
Status: Downloaded newer image for alpine:latest
---> 965ea09ff2eb
Step 2/3 : ENV ADMIN_USER="mark"
---> Running in 5d34f829a387
Removing intermediate container 5d34f829a387
---> e9c50b16c0e1
Step 3/3 : RUN unset ADMIN_USER
---> Running in dbcf57ca390d
Removing intermediate container dbcf57ca390d
---> 2cb4de2e0257
Successfully built 2cb4de2e0257
Successfully tagged alpine:envtest
$ docker run --rm alpine:envtest sh -c 'echo $ADMIN_USER'
mark
ENV
都说相同的“正在移除
中间容器 ”和
RUN
.
docker
,别以为它那么老:
$ docker --version
Docker version 19.03.5, build 633a0ea
RUN instruction
和
RUN command
是另一回事吗?
ENV
,
RUN
- 他们是否创建层、图像或容器?
最佳答案
Docker
作为基于镜像和容器两个主要概念的容器化系统。它们之间的主要区别是顶部可写层。当您生成一个新容器时,新的可写层将放在最后一个图像层之上。这一层通常称为容器层。
所有底层图像内容保持不变,运行容器中的每个更改(创建新文件、修改现有文件等)都将复制到这个薄的可写层中。
在这种情况下,Docker 只存储实际的容器数据和一个镜像实例,从而减少了存储使用并简化了底层工作流程。我将它与C语言中的静态和动态链接进行比较,因此Docker使用动态链接。
图片是layers的组合.每一层只是与它之前的层的一组差异。
文档说:
Only the instructions RUN, COPY, ADD create layers. Other instructions create temporary intermediate images, and do not increase the size of the build.
WORKDIR
如果给定的路径不存在,则创建给定的路径并将目录更改为该路径。如果创建了新路径
WORKDIR
将生成一个新层。
ENV
不会导致图层创建。数据将永久存储在图像和容器配置中,没有简单的方法可以摆脱它。基本上,有两个选项,如何组织工作流:
RUN
结束之前可用。指令:RUN export NAME='megatron' && echo $NAME # 'megatron'
RUN echo $NAME # blank
ENV NAME='megatron'
# some instructions
ENV NAME=''
RUN echo $NAME
RUN
任何不更改文件系统内容的命令都不会触发永久层的创建。考虑以下
Dockerfile
:
FROM alpine:latest
RUN echo "Hello World" # no layer
RUN touch file.txt # new layer
WORKDIR /no/existing/path # new layer
Step 1/4 : FROM alpine:latest
---> 965ea09ff2eb
Step 2/4 : RUN echo "Hello World"
---> Running in 451adb70f017
Hello World
Removing intermediate container 451adb70f017
---> 816ccbd1e8aa
Step 3/4 : RUN touch file.txt
---> Running in 9edc6afdd1e5
Removing intermediate container 9edc6afdd1e5
---> ea0040ec0312
Step 4/4 : WORKDIR /no/existing/path
---> Running in ec0feaf6710d
Removing intermediate container ec0feaf6710d
---> f2fe46478f7c
Successfully built f2fe46478f7c
Successfully tagged envtest:lastest
inspect
用于检查 Docker 对象的命令:
docker inspect --format='{{json .RootFS.Layers}}' <image_id>
RUN
命令 Docker 需要使用中间镜像实例化一个容器,直到 Dockerfile 的那一行并运行实际命令。然后它将容器的状态作为新的中间镜像“提交”并继续构建过程。
关于docker - ENV、RUN 生成层、图像或容器? (理解文档问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59264643/
这个问题已经有答案了: env-cmd error failed to locate ./.env file in gatsby? (14 个回答) 已关闭 3 年前。 我正在学习 Gatsby 教程
我正在尝试使用 mgcv-package,但 mgcv::gam-function 只返回一条错误消息 Tmean = c(1,3,10,5,7) prec = c(300,500,700,600,5
在 Laravel 6 中 Documentation Application Key的第二段是这样写的 Typically, this string should be 32 characters
我试图在创建消息时传递 sns 主题。但根据创建的变量,arn 可能会有所不同。 例如,在环境变量中,我将有 3 个人及其主题。 john = arn:xxxxxxxx sally= arn:xxxx
我开始学习 Angular2,我发现在示例中它们覆盖了配置文件中的 process.env.NODE_ENV 和 process.env.ENV 变量。此代码来自 this example 的 web
我从头开始创建了一个Kotlin原生应用程序,我得到了上面的错误。我怎么才能解决这个问题呢?这是一款简单的“Hello World”应用程序。我有其他计算机,但该错误没有出现在那里。我认为这与科南没有
我有一个 Dockerfile,我在其中设置了一些环境变量(在我运行容器时使用)。一些环境变量依赖于以前的环境变量。当我可以替换为一个变量时,我想保持干爽并避免多次对环境变量的值进行硬编码。 在这个简
我正在学习 Docker 并面临将一个 env 变量的值替换为另一个 env 变量的问题。 这是我的 Dockerfile FROM ubuntu ENV var_env=Tarun ENV comm
我正在将一个项目从 Symfony 2.3 升级到 Symfony 3.4,我对 .env 和 .env.dist 文件之间的关系有点困惑。据我了解,它们之间的关系与Symfony2中paramete
在 python 中,有没有办法从特定的 .env 文件中检索 env 变量的值?例如,我有多个 .env 文件,如下所示: .env.a .env.a ... 我在 .env.b 中有一个名为 IN
我假设我的身份验证服务无法加载配置文件,从而导致错误。我正在关注 AUTH0 上的教程。这是链接 https://auth0.com/blog/real-world-angular-series-pa
我正在使用 base.env 作为我的几个 docker 服务的 env_file。在这个 base.env 中,我有几个部分的环境变量在整个文件中重复。例如,对于三个不同的环境变量,port 和 i
我正在尝试使用 values.SecretValue() 设置我的 aws 存储桶名称。要设置 Django 的媒体 url,我过去使用过: AWS_STORAGE_BUCKET_NAME = val
我通过从PowerShell运行$env:path ="$($env:path);."来“解决”一个问题。显然,它将当前目录添加到了我的路径。请添加到哪个路径变量?在我的环境变量对话框中,我会在哪里看
我有一个很长的自定义应用程序配置文件,用于在工作站上运行的应用程序,其中一些文本元素必须在系统之间手动更改。 这个脚本是为了让我的生活更轻松 - $content = Get-Content("C:\
因为我使用docker和docker-compose而不是Homestead和任何基于Vargrant的开发解决方案,所以我想避免与laravel在.env文件的使用上发生冲突。因此,我希望larav
当我尝试最后一个例子时 perlfaq5: How-do-I-count-the-number-of-lines-in-a-file?我收到一条错误消息。我应该怎样做才能使脚本正常工作? #!/usr
我试图理解为什么当我从我的 .env 文件中明确删除或注释掉它们时,我的 Docker 容器中的 env 变量仍然出现。我是 Docker 的新手,不知道这是预期的行为还是异常。 我的系统设置方式是,
我正在使用 PHP 和 Laravel 框架,我使用 .env 来设置我的环境变量。然后我从我的 PHP 环境调用 python 脚本,并将结果返回给 PHP。我的问题是,在 Python 中设置的默
我安装了 Anaconda 并创建了一个新环境(“dell_proj”)。然后我用我的新环境在 Pycharm 中创建了一个新项目。我的期望是我只能在这个项目中使用我通过 Conda 在特定环境中安装
我是一名优秀的程序员,十分优秀!