繁体   English   中英

如何在 Dockerfile 中使用 here-strings?

[英]how to use here-strings in the Dockerfile?

我正在尝试使用 Dockerfile 在 debian:buster 中安装 mysql-server,如下面的代码所示:

Dockerfile:

From debian:buster

RUN apt update

RUN apt install -y gnupg wget lsb-release

RUN wget https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.deb

RUN printf "1\n1\n4\n" | dpkg -i mysql-apt-config_0.8.13-1_all.deb

RUN apt update

RUN debconf-set-selections <<< 'mysql-community-server mysql-community-server/root-pass password your_password'

RUN debconf-set-selections <<< 'mysql-community-server mysql-community-server/re-root-pass password your_password'

RUN apt-get -y install mysql-server

CMD bash

我想以非交互方式安装它(不会被问到任何配置问题),所以我使用了 debconf 命令来做到这一点,但是当我尝试在 Dockerfile 中使用 RUN 运行它时它不起作用,并且此错误发生在建造 :

在此处输入图片说明

那么如何在 Dockerfile 中使用 here-strings 呢?

你不需要这里的字符串。 您之前已经在 Dockerfile 中使用了替代方案。

RUN printf '%s\n' 'mysql-community-server mysql-community-server/root-pass password your_password' | debconf-set-selections
RUN printf '%s\n' 'mysql-community-server mysql-community-server/re-root-pass password your_password' | debconf-set-selections

echo在其他符合 POSIX 的实现中的行为不一致; 更喜欢printf

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM