如何在Dockerfile中使用多行编写命令,同时保留新行?
我想在Dockerfile中写入下面的RUN命令。 但是,docker工人并没有保留新的线路。
RUN echo "[repo] \ name = YUM Repository \ baseurl = https://example.com/packages/ \ enabled = 1 \ gpgcheck = 0" > /etc/yum.repos.d/Repo.repoxyz
我知道在每一行的结尾都会有新的一行。 但是,有没有什么办法可以写出多行保留新的行。
用$'
开始你的命令,用$'
结束'
并用\n\
作为换行符,如下所示:
RUN echo $'[repo] \n\ name = YUM Repository \n\ baseurl = https://example.com/packages/ \n\ enabled = 1 \n\ gpgcheck = 0' > /etc/yum.repos.d/Repo.repoxyz
我用printf
。 使用“\ n”将所有文本写入一行。
执行:
RUN printf 'example \ntext \nhere' >> example.txt
刀片:
example text here
在example.txt中