如何在长docker RUN命令中添加注释? [英] How can I add comments in long docker RUN commands?
问题描述
我知道在docker文件中使用运行RUN命令以减少步骤/空间的习惯.但是,随着这些内容变长,我还想添加更多注释以使命令清晰明了.
从FROM版本:18.04ENV DEBIAN_FRONTEND =非交互式运行apt-get update \#我想评论一下此步骤在做什么&&apt-get install -y software-properties-common#斜线之前的注释在这里也不起作用\
允许在单个步骤旁边添加注释的docker/bash语法或docker约定是什么?如果我将注释放在上面指示的位置,则会出现错误
$ sudo docker build.将构建上下文发送到Docker守护程序4.608kB来自守护程序的错误响应:Dockerfile分析错误行5:未知指令:&&
从bash的角度来看,这是有道理的,但我几乎没有其他选择可以传达该行的意图.
您只需要在一行中添加注释:
#评论1运行apt获取更新#评论2&&apt-get install blabla blabla blabla \#评论3&&回声这不是操练
docker删除带有换行符的注释行.
有关示例,请参见 docker-nginx ./p>
I know it's customary to have run-on RUN commands in docker files to reduce steps/space. However, as these get long, I'd also like to add more comments to make the command clear.
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \ # I WANT A COMMENT on what this step is doing
&& apt-get install -y software-properties-common # comments also don't work here, before the slash \
What's the docker/bash syntax or docker convention that would allow comments next to individual steps? If I put the comment where indicated above, I get the error
$ sudo docker build .
Sending build context to Docker daemon 4.608kB
Error response from daemon: Dockerfile parse error line 5: unknown instruction: &&
Which makes sense from a bash perspective but leaves me with few options for communicating the intent of the line.
You need to have a line with only the comment:
# comment 1
RUN apt-get update \
# comment 2
&& apt-get install blabal blabla blabla \
# comment 3
&& echo this is not a drill
docker removes the comment line with the newline.
See docker-nginx with examples.
这篇关于如何在长docker RUN命令中添加注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!