【问题标题】:Can't build openjdk:8-jdk image directly无法直接构建 openjdk:8-jdk 镜像
【发布时间】:2017-03-20 23:34:41
【问题描述】:

我正在慢慢学习 Riot 控制你的 Docker Image 教程http://engineering.riotgames.com/news/taking-control-your-docker-image。本教程有点旧,所以最终文件的外观有一些明确的变化。在碰了几堵墙后,我决定按照教程的相反顺序工作。我成功地将jenkinsci官方镜像折叠到我的个人Dockerfile中,从FROM: openjdk:8-dk开始。但是当我尝试将 openjdk:8-dk 文件折叠到我的个人图像中时,我收到以下错误

E:未找到“openjdk-8-jdk”的版本“8u102-b14.1-1~bpo8+1” 错误:服务“jenkinsmaster”未能构建:命令“/bin/sh” -c set -x && apt-get update && apt-get install -y openjdk-8-jdk="$JAVA_DEBIAN_VERSION" ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" && rm -rf /var/lib/apt/lists/* && [ "$JAVA_HOME" = "$(docker-java-home)" ]' 返回一个非零代码:100 Cosettes-MacBook-Pro:docker-test 珂赛特$

即使我放弃并直接将 openjdk:8-jdk Dockerfile 复制并粘贴到我自己的文件中,我也会收到此错误。我的最终目标是将我的个人 Dockerfile 降低到从 debian-jessie 开始的程度。任何帮助将不胜感激。

我的 Dockerfile:

FROM buildpack-deps:jessie-scm

# A few problems with compiling Java from source:
#  1. Oracle.  Licensing prevents us from redistributing the official JDK.
#  2. Compiling OpenJDK also requires the JDK to be installed, and it gets
#       really hairy.

RUN apt-get update && apt-get install -y --no-install-recommends \
        bzip2 \
        unzip \
        xz-utils \
    && rm -rf /var/lib/apt/lists/*

RUN echo 'deb http://deb.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/jessie-backports.list

# Default to UTF-8 file.encoding
ENV LANG C.UTF-8

# add a simple script that can auto-detect the appropriate JAVA_HOME value
# based on whether the JDK or only the JRE is installed
RUN { \
        echo '#!/bin/sh'; \
        echo 'set -e'; \
        echo; \
        echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
    } > /usr/local/bin/docker-java-home \
    && chmod +x /usr/local/bin/docker-java-home

ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64

ENV JAVA_VERSION 8u102
ENV JAVA_DEBIAN_VERSION 8u102-b14.1-1~bpo8+1

# see https://bugs.debian.org/775775
# and https://github.com/docker-library/java/issues/19#issuecomment-70546872
ENV CA_CERTIFICATES_JAVA_VERSION 20140324

RUN set -x \
    && apt-get update \
    && apt-get install -y \
        openjdk-8-jdk="$JAVA_DEBIAN_VERSION" \
        ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
    && rm -rf /var/lib/apt/lists/* \
    && [ "$JAVA_HOME" = "$(docker-java-home)" ]

# see CA_CERTIFICATES_JAVA_VERSION notes above
RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure

# Jenkins Specifics

# install Tini
ENV TINI_VERSION 0.9.0
ENV TINI_SHA fa23d1e20732501c3bb8eeeca423c89ac80ed452

# Use tini as subreaper in Docker container to adopt zombie processes
RUN curl -fsSL https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static -o /bin/tini && chmod +x /bin/tini \
  && echo "$TINI_SHA  /bin/tini" | sha1sum -c -

# Set Jenkins Environmental Variables
ENV JENKINS_HOME /var/jenkins_home
ENV JENKINS_SLAVE_AGENT_PORT 50000
    # jenkins version being bundled in this docker image
ARG JENKINS_VERSION
ENV JENKINS_VERSION ${JENKINS_VERSION:-2.19.1}
    # jenkins.war checksum, download will be validated using it
ARG JENKINS_SHA=dc28b91e553c1cd42cc30bd75d0f651671e6de0b
ENV JENKINS_UC https://updates.jenkins.io
ENV COPY_REFERENCE_FILE_LOG $JENKINS_HOME/copy_reference_file.log
ENV JAVA_OPTS="-Xmx8192m"
ENV JENKINS_OPTS="--handlerCountMax=300 --logfile=/var/log/jenkins/jenkins.log  --webroot=/var/cache/jenkins/war"
    # Can be used to customize where jenkins.war get downloaded from
ARG JENKINS_URL=http://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war
ARG user=jenkins
ARG group=jenkins
ARG uid=1000
ARG gid=1000

# Jenkins is run with user `jenkins`, uid = 1000. If you bind mount a volume from the host or a data
# container, ensure you use the same uid.
RUN groupadd -g ${gid} ${group} \
    && useradd -d "$JENKINS_HOME" -u ${uid} -g ${gid} -m -s /bin/bash ${user}

# Jenkins home directory is a volume, so configuration and build history
# can be persisted and survive image upgrades
VOLUME /var/jenkins_home

# `/usr/share/jenkins/ref/` contains all reference configuration we want
# to set on a fresh new installation. Use it to bundle additional plugins
# or config file with your custom jenkins Docker image.
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d

# Install Jenkins. Could use ADD but this one does not check Last-Modified header neither does it
# allow to control checksum. see https://github.com/docker/docker/issues/8331
RUN curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war \
  && echo "${JENKINS_SHA}  /usr/share/jenkins/jenkins.war" | sha1sum -c -

# Prep Jenkins Directories
USER root
RUN chown -R ${user} "$JENKINS_HOME" /usr/share/jenkins/ref
RUN mkdir /var/log/jenkins
RUN mkdir /var/cache/jenkins
RUN chown -R ${group}:${user} /var/log/jenkins
RUN chown -R ${group}:${user} /var/cache/jenkins

# Expose ports for web (8080) & node (50000) agents
EXPOSE 8080
EXPOSE 50000

# Copy in local config filesfiles
COPY init.groovy /usr/share/jenkins/ref/init.groovy.d/tcp-slave-agent-port.groovy
COPY jenkins-support /usr/local/bin/jenkins-support
COPY jenkins.sh /usr/local/bin/jenkins.sh
    # NOTE : Just set pluginID to download latest version of plugin.
    # NOTE : All plugins need to be listed as there is no transitive dependency resolution.
    # from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup
    # /usr/share/jenkins/ref/plugins from a support bundle
COPY plugins.sh /usr/local/bin/plugins.sh
RUN chmod +x /usr/local/bin/plugins.sh
RUN chmod +x /usr/local/bin/jenkins.sh

# Switch to the jenkins user
USER ${user}

# Tini as the entry point to manage zombie processes
ENTRYPOINT ["/bin/tini", "--", "/usr/local/bin/jenkins.sh"]

【问题讨论】:

  • 你能试试8u111-b14-2~bpo8+1的JAVA_DEBIAN_VERSION吗?该软件包已在 Debian 的存储库中进行了安全更新。我不确定有安全漏洞的旧包是否保留在 debian 的包存储库中。
  • 这完全有效。做一个答案,这样我就可以为你选择?知道为什么在我的 Dockerfile 中使用 FROM 语句调用时应该完全相同的代码在粘贴到同一个 Dockerfile 时不起作用吗?

标签: jenkins docker openjdk


【解决方案1】:

尝试JAVA_DEBIAN_VERSION8u111-b14-2~bpo8+1

会发生以下情况:当您构建 docker 文件时,docker 会尝试执行 dockerfile 中的所有行。其中之一就是这个 apt 命令:apt-get install -y openjdk-8-jdk="$JAVA_DEBIAN_VERSION"。该命令说“完全安装 OpenJDK 版本 $JAVA_DEBIAN_VERSION。没有别的。”。此版本不再在 Debian 存储库中可用,因此无法 apt-get 安装!我相信官方镜像中的所有软件包都会发生这种情况:如果发布了新版本的软件包,则不再安装旧版本。

如果您想访问较旧的 Debian 软件包,您可以使用 http://snapshot.debian.org/ 之类的东西。较旧的 OpenJDK 软件包具有已知的安全漏洞。我建议使用最新版本。

您可以通过在 apt-get 命令中省略显式版本来使用最新版本。另一方面,这会降低您的图像的可重复性:今天构建图像可能会得到 u111,明天构建图像可能会得到 u112。

至于为什么指令在其他 Dockerfile 中起作用,我认为原因是在构建其他 Dockerfile 时,该包是可用的。所以docker可以apt-get install它。然后 Docker 构建了包含(较旧的)OpenJDK 的映像。该图像是二进制文件,因此您可以安装它,或在FROM 中使用它而不会出现任何问题。但是您无法重现该图像:如果您尝试自己构建相同的图像,您会遇到相同的错误。

这也带来了一个关于安全更新的问题:由于 docker 镜像实际上是静态二进制文件(构建一次,捆绑所有依赖项),一旦构建它们就不会获得安全更新。您需要跟踪影响您的 docker 镜像的任何安全更新并重建任何受影响的 docker 镜像。

【讨论】:

  • 感谢您的透彻解释!
猜你喜欢
  • 2017-09-15
  • 2019-03-15
  • 2020-08-04
  • 2012-03-30
  • 1970-01-01
  • 2022-12-11
  • 2020-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多