无法直接构建openjdk:8-jdk图像

时间:2016-11-07 15:03:38

标签: jenkins docker openjdk

我正在慢慢地通过你的Docker Image教程http://engineering.riotgames.com/news/taking-control-your-docker-image的骚乱控制。本教程有点陈旧,因此对结束文件的外观有一些明确的改变。在碰到几面墙之后,我决定按照教程的相反顺序工作。我成功地将官方jenkinsci图像折叠到我的个人Dockerfile中,从FROM:openjdk:8-dk开始。但是当我尝试将openjdk:8-dk文件折叠到我的个人图像中时,我收到以下错误

  

E:版本' 8u102-b14.1-1~bpo8 + 1'对于' openjdk-8-jdk'没找到   错误:服务' jenkinsmaster'无法构建:命令' / bin / sh   -c set -x&& apt-get update&& apt-get install -y openjdk-8-jdk =" $ JAVA_DEBIAN_VERSION"         CA证书的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"]

1 个答案:

答案 0 :(得分:1)

尝试JAVA_DEBIAN_VERSION 8u111-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镜像。