如何在Dockerfile中使用here-strings? [英] how to use here-strings in the Dockerfile?

查看:319
本文介绍了如何在Dockerfile中使用here-strings?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to install mysql-server in debian:buster using Dockerfile as you can see in the following code :

Dockerfile:

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运行它时,它不起作用,并且在构建过程中发生了此错误:

and I wanted to install it non-interactively (without being asked any configuration questions), so I used debconf command, to do that but It doesn't work when I try to run it with RUN in the Dockerfile and this error occurs during the build :

那么如何在Dockerfile中使用here字符串?

So how can I use the here-strings in the Dockerfile?

推荐答案

您不需要这里的字符串。

You don't need here-strings. You are already using the alternative earlier in your 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

echo doesn't behave consistently across otherwise POSIX-compliant implementations; prefer printf instead.

这篇关于如何在Dockerfile中使用here-strings?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆