gpt4 book ai didi

bash - 如何在长 docker RUN 命令中添加注释?

转载 作者:IT老高 更新时间:2023-10-28 21:43:15 32 4
gpt4 key购买 nike

我知道习惯上在 docker 文件中运行 RUN 命令以减少步骤/空间。但是,随着这些内容变得很长,我还想添加更多注释以使命令清晰。

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 \

允许在单个步骤旁边添加注释的 docker/bash 语法或 docker 约定是什么?如果我把评论放在上面指出的地方,我会收到错误

$ sudo docker build .
Sending build context to Docker daemon 4.608kB
Error response from daemon: Dockerfile parse error line 5: unknown instruction: &&

这从 bash 的角度来看是有道理的,但让我没有多少选择来传达线路的意图。

最佳答案

你需要有一行只有评论:

# comment 1
RUN apt-get update \
# comment 2
&& apt-get install blabal blabla blabla \
# comment 3
&& echo this is not a drill

docker 使用换行符删除注释行。

docker-nginx举例。

关于bash - 如何在长 docker RUN 命令中添加注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53564598/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com