Docker 失败,子进程 /usr/bin/dpkg 返回错误代码 (1)

2022-09-02 02:51:23

我在尝试将JRE安装到我的docker容器中时遇到问题。

我不断收到错误消息;

Processing triggers for libc-bin (2.28-10) ...
Processing triggers for systemd (241-7~deb10u1) ...
Processing triggers for ca-certificates (20190110) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

done.
done.
Processing triggers for libgdk-pixbuf2.0-0:amd64 (2.38.1+dfsg-1) ...
Errors were encountered while processing:
 openjdk-11-jre-headless:amd64
 openjdk-11-jre:amd64
 default-jre
E: Sub-process /usr/bin/dpkg returned an error code (1)

如果我向上滚动一点构建输出,我也会看到以下问题;

Setting up default-jre-headless (2:1.11-71) ...
Setting up openjdk-11-jre-headless:amd64 (11.0.4+11-1~deb10u1) ...
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/rmid to provide /usr/bin/rmid (rmid) in auto mode
update-alternatives: error: error creating symbolic link '/usr/share/man/man1/rmid.1.gz.dpkg-tmp': No such file or directory
dpkg: error processing package openjdk-11-jre-headless:amd64 (--configure):
 installed openjdk-11-jre-headless:amd64 package post-installation script subprocess returned error exit status 2
dpkg: dependency problems prevent configuration of openjdk-11-jre:amd64:
 openjdk-11-jre:amd64 depends on openjdk-11-jre-headless (= 11.0.4+11-1~deb10u1); however:
  Package openjdk-11-jre-headless:amd64 is not configured yet.

dpkg: error processing package openjdk-11-jre:amd64 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of default-jre:
 default-jre depends on openjdk-11-jre; however:
  Package openjdk-11-jre:amd64 is not configured yet.

dpkg: error processing package default-jre (--configure):
 dependency problems - leaving unconfigured
Setting up ca-certificates-java (20190405) ...
head: cannot open '/etc/ssl/certs/java/cacerts' for reading: No such file or directory

我的Dockerfile非常简单,但它就是不起作用

FROM nginx:latest

RUN apt-get update -y && apt-get install -y \
    unzip \
    wget \
    default-jre \
    nginx

它看起来正在使用,任何帮助使它工作将不胜感激。我已经尝试了好几天了。debian buster


答案 1

jre安装需要文件夹存在于服务器上,请尝试以下操作:man

FROM nginx:latest

RUN mkdir -p /usr/share/man/man1

RUN apt-get update -y && apt-get install -y \
    unzip \
    wget \
    default-jre \
    nginx

答案 2

以下是有关此问题的一些背景信息。发生这种情况是因为安装后脚本尝试为java运行,并且该文件夹不存在,正如LinPy的答案中已经解释的那样。update-alternatives/usr/share/man/man1

以下 Debian bug 更详细地讨论了这个问题,并通过创建它们 issing 文件夹记录了解决方法:https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863199#23

似乎这个问题最近在OpenJDK 8中关闭了,但它似乎在较新的JDK中仍然开放,请参阅:

https://salsa.debian.org/openjdk-team/openjdk/-/blob/master/debian/JB-jdk-headless.postinst.in

以下补丁可以解决此问题,并且可能也应该添加到较新的OpenJDK版本中:

diff --git a/debian/JB-jdk-headless.postinst.in b/debian/JB-jdk-headless.postinst.in
index 0e1ef5f..e3afef1 100644
--- a/debian/JB-jdk-headless.postinst.in
+++ b/debian/JB-jdk-headless.postinst.in
@@ -43,6 +43,7 @@ configure)
     if [ -n "$multiarch" ] && [ "$DPKG_MAINTSCRIPT_ARCH" != $(dpkg --print-architecture) ]; then
        priority=$(expr $priority - 1)
     fi
+    test -d /usr/share/man/man1 || mkdir -p /usr/share/man/man1
     for i in $jdk_hl_tools; do
        unset slave1 slave2 || true
         if [ -e $mandir/man1/$i.$srcext ]; then

推荐