代码之家  ›  专栏  ›  技术社区  ›  Mittenchops

如何在长docker运行命令中添加注释?

  •  0
  • Mittenchops  · 技术社区  · 7 年前

    我知道在docker文件中使用run-on-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的角度来看,这是有道理的,但对于传达这一行的意图,我没有多少选择。

    1 回复  |  直到 7 年前
        1
  •  17
  •   wisbucky Ishan    7 年前

    # 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 举例说明。

        2
  •  4
  •   wisbucky Ishan    7 年前

    RUN apt-get update -y          `# comment1` \ 
    && apt-get install -y          `# comment2` \
        software-properties-common `# comment3` \
        curl                       `# comment4`
    

    或

    RUN apt-get update -y          $(: comment1) \ 
    && apt-get install -y          $(: comment2) \
        software-properties-common $(: comment3) \
        curl                       $(: comment4)
    
    推荐文章