podman build
由于 Docker 清理操作和内存分配错误而失败。
我的简化容器文件是:
FROM docker.io/php:8.1-apache
RUN apt-get update
CMD ["apache2-foreground"]
这有一个错误Problem executing scripts APT::Update::Post-Invoke
,显然是由 Docker 清理操作引起的。
STEP 1: FROM docker.io/php:8.1-apache
STEP 2: RUN apt-get update
Get:1 http://deb.debian.org/debian bookworm InRelease [147 kB]
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8904 kB]
Get:5 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [4732 B]
Get:6 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [48.0 kB]
Fetched 9204 kB in 1s (8706 kB/s)
Reading package lists...
E: Problem executing scripts APT::Update::Post-Invoke 'rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true'
E: Sub-process returned an error code
Error: error building at STEP "RUN apt-get update": error while running runtime: exit status 100
可以通过添加 来禁用 Docker cleanup 命令RUN mv /etc/apt/apt.conf.d/docker-clean /etc/apt/apt.conf.d/docker-clean.disabled
,但这不是必需的。我们如何正确解决这个问题?以下Containerfile
构建和容器将运行。
FROM docker.io/php:8.1-apache
RUN mv /etc/apt/apt.conf.d/docker-clean /etc/apt/apt.conf.d/docker-clean.disabled
RUN apt-get update
CMD ["apache2-foreground"]
但是,添加其他 apt-get 命令会导致内存分配错误。尝试添加失败apt-get upgrade -y
,甚至apt-get install -y wget
如下所示:
FROM docker.io/php:8.1-apache
RUN mv /etc/apt/apt.conf.d/docker-clean /etc/apt/apt.conf.d/docker-clean.disabled
RUN apt-get update
RUN apt-get install -y wget
CMD ["apache2-foreground"]
在构建结果中,请注意lzma error: Cannot allocate memory
尝试解压缩 wget 存档时的情况。
STEP 1: FROM docker.io/php:8.1-apache
STEP 2: RUN mv /etc/apt/apt.conf.d/docker-clean /etc/apt/apt.conf.d/docker-clean.disabled
--> Using cache 19e055f778a12ee0e7bdc3b0474e8013dddf7763ffdee6d7c51b04854dbbe48c
--> 19e055f778a
STEP 3: RUN apt-get update
--> Using cache 9acf978dd9eae527716a6684a2f71068005d047526398bf1b74d811e7e3ca006
--> 9acf978dd9e
STEP 4: RUN apt-get install -y wget
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
wget
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 984 kB of archives.
After this operation, 3692 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main amd64 wget amd64 1.21.3-1+b2 [984 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 984 kB in 0s (21.4 MB/s)
dpkg-deb (subprocess): decompressing archive '/var/cache/apt/archives/wget_1.21.3-1+b2_amd64.deb' (size=983848) member 'control.tar': lzma error: Cannot allocate memory
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
dpkg-deb: error: tar subprocess returned error exit status 2
dpkg: error processing archive /var/cache/apt/archives/wget_1.21.3-1+b2_amd64.deb (--unpack):
dpkg-deb --control subprocess returned error exit status 2
Errors were encountered while processing:
/var/cache/apt/archives/wget_1.21.3-1+b2_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
Error: error building at STEP "RUN apt-get install -y wget": error while running runtime: exit status 100
似乎有大量可用内存。以下是来自上面的版本,我们通过禁用 Docker 清理来设法运行,但尚未执行其他 apt-get 操作。
root@pod_leask:/var/www/html# free
total used free shared buff/cache available
Mem: 24494592 6875476 14715284 128916 3444304 17619116
Swap: 33554428 0 33554428
答案1
事实证明,FROM docker.io/php:8.1-apache
创建了一个 Debian 12(书虫)容器,但我们的主机运行的是 Debian 11(牛眼)。我们强制容器使用 bullseye,以便它通过使用 与主机匹配FROM docker.io/php:8.1-apache-bullseye
。 docker-clean 问题和无法分配内存问题都消失了。
这是我们新的工作容器文件。 (当然我们的完整文件比这个更复杂,但它也有效)
FROM docker.io/php:8.1-apache-bullseye
RUN apt-get update
RUN apt-get install -y wget
CMD ["apache2-foreground"]
然而,为什么这很重要呢?靶心和书呆子之间是否存在影响容器的核心差异?我认为容器应该独立于 Debian 版本。强制使用相同的版本可以解决眼前的问题,因此我将考虑解决此问题并继续。