我正在使用 Dockerfile 构建一个 Docker 映像来构建它。我已将ARG DEBIAN_FRONTEND=noninteractive
Dockerfile 放在开头以避免构建时出现 debconf 警告。
apt-get install
在 Dockerfile 中使用时不会显示警告。但是,当从包含 apt-get install 命令的 Dockerfile 执行 sh 脚本 (install_dependencies.sh) 时,警告会再次出现。我还尝试DEBIAN_FRONTEND=noninteractive
在 sh 脚本本身内部进行设置。
我可以通过在 apt-get install 命令之前添加 sh 脚本来解决这个问题,echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections
但我想避免这种情况,因为脚本中的任何失败都会使 debconf 选择变为非交互式。
Dockerfile:
FROM ubuntu:18.04
# Avoid warnings by switching to noninteractive
ARG DEBIAN_FRONTEND=noninteractive
WORKDIR /tmp
# Configure APT --> HERE THE WARNINGS 'debconf: unable to initialize frontend: Dialog' ARE NOT DISPLAYED
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get install -y \
apt-utils \
dialog \
fakeroot \
software-properties-common \
2>&1
# Install APT packages --> HERE THE WARNINGS 'debconf: unable to initialize frontend: Dialog' ARE NOT DISPLAYED
RUN apt-get update && apt-get install -y \
#
# System packages
iproute2 \
procps \
lsb-release \
sudo \
unattended-upgrades \
dnsutils \
iputils-ping \
xauth \
openssl \
tar \
zip \
#
# Helpers
&& apt-get install -y \
ca-certificates \
curl \
wget \
lsof \
gconf2 \
gconf-service \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# Install LTE stack dependencies --> HERE THE WARNINGS 'debconf: unable to initialize frontend: Dialog' ARE DISPLAYED
RUN chmod +x install_dependencies.sh \
&& export DEBIAN_FRONTEND=noninteractive; ./install_dependencies.sh
install_dependencies.sh:
#!/bin/sh
export DEBIAN_FRONTEND=noninteractive
APT_PACKAGES="lib32z1 \
python-setuptools \
libmysqlclient-dev \
ninja-build"
install_apt_packages() {
sudo apt-get install -y tzdata \
build-essential \
git
for package in $APT_PACKAGES;
do
sudo apt-get -y install "$package";
done
}
main() {
sudo apt-get update && sudo apt-get upgrade -y
install_apt_packages
}
main
编辑:感谢@arkadiusz-drabczyk告诉我从 apt-get 命令中删除 sudo ,他所说的完全有道理,环境变量在执行命令之前下降。