[英]Multiline heredoc with sudo in Dockerfile
We use our local repo in sources.list, and for 20.04 it required to add in apt.conf.d
Acquire::https::local_repo.local_host.com::Verify-Peer "false";
我们在 sources.list 中使用我们的本地仓库,对于 20.04,它需要添加
apt.conf.d
Acquire::https::local_repo.local_host.com::Verify-Peer "false";
With Bash it works, as using,使用 Bash 它可以使用,
sudo tee -a /etc/apt/apt.conf.d/80ssl-exceptions > /dev/null <<'EOF'
Acquire::https::local_repo.local_host.com::Verify-Peer "false";
EOF
But I don't find a solution to do it for Dockerfile.但我没有为 Dockerfile 找到解决方案。 I've tried it with different escape character/new line and so on, but always unsuccessful.
我已经尝试过使用不同的转义字符/换行符等,但总是不成功。 For example,
例如,
sudo tee -a /etc/apt/apt.conf.d/80ssl-exceptions > /dev/null <<'EOF' \
Acquire::https::local_repo.local_host.com::Verify-Peer "false"; \
EOF
Results - /bin/sh: 1: EOF: not found
结果 -
/bin/sh: 1: EOF: not found
To note that cat
or echo
is not an option, also adding those 3 line in a script is also not preferable.要注意
cat
或echo
不是一个选项,在脚本中添加这 3 行也不可取。
If you only have one line to append then I wouldn't use a heredoc.如果你只有一行 append 那么我不会使用heredoc。 It's simpler to use
echo
:使用
echo
更简单:
RUN echo 'Acquire::https::local_repo.local_host.com::Verify-Peer "false";' | \
sudo tee -a /etc/apt/apt.conf.d/80ssl-exceptions > /dev/null
Or cat
:或
cat
:
RUN cat <<< 'Acquire::https::local_repo.local_host.com::Verify-Peer "false";' | \
sudo tee -a /etc/apt/apt.conf.d/80ssl-exceptions > /dev/null
Or send the string directly to sudo tee
:或将字符串直接发送到
sudo tee
:
RUN sudo tee -a /etc/apt/apt.conf.d/80ssl-exceptions > /dev/null \
<<< 'Acquire::https::local_repo.local_host.com::Verify-Peer "false";'
Note that the latter two options may require you to also set SHELL /bin/bash
since <<<
is a bash-ism not available in plain sh
.请注意,后两个选项可能还需要您设置
SHELL /bin/bash
因为<<<
是普通sh
中不可用的 bash-ism。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.