【发布时间】:2022-08-11 12:58:43
【问题描述】:
当我接手一个项目时,我在 Dockerfile 中发现了一个命令“RUN true”。
FROM xxx
RUN xxx
RUN true
RUN xxx
我不知道这个命令是做什么的,谁能帮忙解释一下。在我看来,这个命令没有意义,但我不确定是否还有其他用途。
有关于Creating Images 的文档,你可以看到它:
RUN true \\
&& dnf install -y --setopt=tsflags=nodocs \\
httpd vim \\
&& systemctl enable httpd \\
&& dnf clean all \\
&& true
@大卫迷宫
测试它。码头文件:
FROM centos:7.9.2009
RUN yum install tmux -y
RUN yum install not_exists -y
构建日志:
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM centos:7.9.2009
---> eeb6ee3f44bd
Step 2/3 : RUN yum install tmux -y
---> Running in 6c6e29ea9f2c
...omit...
Complete!
Removing intermediate container 6c6e29ea9f2c
---> 7c796c2b5260
Step 3/3 : RUN yum install not_exists -y
---> Running in e4b7096cc42b
...omit...
No package not_exists available.
Error: Nothing to do
The command \'/bin/sh -c yum install not_exists -y\' returned a non-zero code: 1
修改dockerfile:
FROM centos:7.9.2009
RUN yum install tmux -y
RUN yum install tree -y
构建日志:
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM centos:7.9.2009
---> eeb6ee3f44bd
Step 2/3 : RUN yum install tmux -y
---> Using cache
---> 7c796c2b5260
Step 3/3 : RUN yum install tree -y
---> Running in 180b32cb44f3
...omit...
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
Removing intermediate container 180b32cb44f3
---> 4e905ed25cc2
Successfully built 4e905ed25cc2
Successfully tagged test:v0
你可以看到Using cache 7c796c2b5260。没有命令 \"RUN true\",但第一个 \"RUN\" 缓存被重用。
标签: dockerfile