bash - 如何在长 docker RUN 命令中添加注释?
问题描述
我知道习惯上在 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示例。
推荐阅读
- ocaml - OCaml 构建工具 dune 已安装,但未运行
- python - 改变检测块层末端yacc的方法
- ios - 如何获得顺序 MKDirection 请求响应 Swift
- php - 使用 ORDER BY 时如何从 mysql 查询中加载更多行以实现无限滚动
- angular - 子路由中的延迟加载模块
- java - 无法自省类 [org.keycloak.adapters.springboot.KeycloakAutoConfiguration]
- c - C警告缺少默认初始化的查找表条目
- google-apps-script - 将整列的数据和格式/样式复制到新选项卡(同一张表)的脚本
- node.js - 使用高效的缓存策略和 nodejs 服务静态资产
- rust - 如何理解 Rust 中函数参数和返回值的生命周期?