繁体   English   中英

Dockerfile 中带有 sudo 的多行 heredoc

[英]Multiline heredoc with sudo in Dockerfile

我们在 sources.list 中使用我们的本地仓库,对于 20.04,它需要添加apt.conf.d Acquire::https::local_repo.local_host.com::Verify-Peer "false";

使用 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

但我没有为 Dockerfile 找到解决方案。 我已经尝试过使用不同的转义字符/换行符等,但总是不成功。 例如,

sudo tee -a /etc/apt/apt.conf.d/80ssl-exceptions > /dev/null <<'EOF' \
Acquire::https::local_repo.local_host.com::Verify-Peer "false"; \
EOF

结果 - /bin/sh: 1: EOF: not found

要注意catecho不是一个选项,在脚本中添加这 3 行也不可取。

如果你只有一行 append 那么我不会使用heredoc。 使用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

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

或将字符串直接发送到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";'

请注意,后两个选项可能还需要您设置SHELL /bin/bash因为<<<是普通sh中不可用的 bash-ism。

暂无
暂无

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

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