我想为 Docker 容器准备环境,这样当apt-get upgrade -s
在容器内运行时,其结果与在主机外部运行命令时相同。这是在添加文本收集器的上下文中并为此做准备apt.sh
到现有的 Prometheus node-exporter
。我已经在使用 KubernetesDaemonSet
来控制此类容器(pod),方式类似于 GitHub 中的示例prometheus-community/node-exporter-textfile-collector-scripts
。
从它的手册页来看,apt-get
它可以处理/etc/apt
、/var/cache/apt
和中的文件,所以我的容器以只读方式从主机挂载这些文件。目前我的主机和容器分别运行 Debian 9 (Stretch) 和 Debian 10 (Buster)。我通过在容器外部和内部/var/lib/apt
运行来解决这个问题。apt-get upgrade -s
apt-get upgrade -s -t stretch
然而两次运行仍然产生不同的结果。我遗漏了什么?
答案1
来自docker官方文档:
APT-GET
Probably the most common use-case for RUN is an application of apt-get. Because it installs packages, the RUN apt-get command has several gotchas to look out for.
Avoid RUN apt-get upgrade and dist-upgrade, as many of the “essential” packages from the parent images cannot upgrade inside an unprivileged container.
If a package contained in the parent image is out-of-date, contact its maintainers.