C/C++ 构建失败时退出 Docker 容器

C/C++ 构建失败时退出 Docker 容器

我想知道当我的应用程序源代码出现错误时退出 Docker 容器是否正常。

我从以前的同事那里继承了那个 Docker 镜像(Ubuntu 18.04),我不知道如果手动调整当应用程序构建失败时强制退出容器,或者这是正常的

谢谢建议

FROM ubuntu:18.04

ENV DEBIAN_FRONTEND=noninteractive \
    JAVA_VERSION=8

RUN  dpkg --add-architecture i386

RUN apt-get update && apt-get install -y \
    gosu \
    adduser \
    adwaita-icon-theme \
    apt \
    autoconf \
    automake \
    autopoint \
    autotools-dev \
    base-files \
    base-passwd \
    bash \
    bc \
    binutils \
    binutils-common \
    binutils-x86-64-linux-gnu \
    bsdmainutils \
    bsdutils \
    bzip2 \
    ca-certificates \
    ca-certificates-java \
    coreutils \
    cpio \
    cpp \
    cpp-7 \
    curl \
    dash \
    debconf \
    debhelper \
    debianutils \
    devscripts \
    dh-autoreconf \
    dh-strip-nondeterminism \
    diffutils \
    dirmngr \
    distro-info-data \
    dos2unix \
    e2fsprogs \
    fdisk \
    file \
    findutils \
    flex \
    fontconfig \
    fontconfig-config \
    fonts-dejavu-core \
    g++ \
    g++-7 \
    g++-7-multilib \
    g++-multilib \
    gawk \
    gcc \
    gcc-7 \
    gcc-7-base \
    gcc-7-multilib \
    gcc-8-base \
    gcc-multilib \
    gettext \
    gettext-base \
    gir1.2-glib-2.0 \
    git \
    git-man \
    gnupg \
    gnupg-l10n \
    gnupg-utils \
    gpg \
    gpg-agent \
    gpg-wks-client \
    gpg-wks-server \
    gpgconf \
    gpgsm \
    gpgv \
    grep \
    groff-base \
    gtk-update-icon-cache \
    guile-2.0-libs \
    gzip \
    hicolor-icon-theme \
    hostname \
    humanity-icon-theme \
    init-system-helpers \
    intltool-debian \
    iso-codes \
    java-common \
    lib32asan4 \
    lib32atomic1 \
    lib32cilkrts5 \
    lib32gcc-7-dev \
    lib32gcc1 \
    lib32gomp1 \
    lib32itm1 \
    lib32mpx2 \
    lib32quadmath0 \
    lib32stdc++-7-dev \
    lib32stdc++6 \
    lib32ubsan0 \
    libacl1 \
    libapr1 \
    libaprutil1 \
    libapt-inst2.0 \
    libapt-pkg5.0 \
    libarchive-zip-perl \
    libasan4 \
    libasn1-8-heimdal \
    libasound2 \
    libasound2-data \
    libassuan0 \
    libasyncns0 \
    libatk-bridge2.0-0 \
    libatk-wrapper-java \
    libatk-wrapper-java-jni \
    libatk1.0-0 \
    libatk1.0-data \
    libatomic1 \
    libatspi2.0-0 \
    libattr1 \
    libaudit-common \
    libaudit1 \
    libavahi-client3 \
    libavahi-common-data \
    libavahi-common3 \
    libbinutils \
    libblkid1 \
    libbsd0 \
    libbz2-1.0 \
    libc-bin \
    libc-dev-bin \
    libc6 \
    libc6-dev \
    libc6-dev-i386 \
    libc6-dev-x32 \
    libc6-i386 \
    libc6-x32 \
    libcairo2 \
    libcap-ng0 \
    libcap2 \
    libcap2-bin \
    libcc1-0 \
    libcilkrts5 \
    libcom-err2 \
    libcroco3 \
    libcups2 \
    libcurl3-gnutls \
    libcurl4 \
    libdatrie1 \
    libdb5.3 \
    libdbus-1-3 \
    libdebconfclient0 \
    libdpkg-perl \
    libdrm-amdgpu1 \
    libdrm-common \
    libdrm-intel1 \
    libdrm-nouveau2 \
    libdrm-radeon1 \
    libdrm2 \
    libedit2 \
    libelf1 \
    liberror-perl \
    libexif12 \
    libexpat1 \
    libext2fs2 \
    libfdisk1 \
    libffi6 \
    libfile-homedir-perl \
    libfile-stripnondeterminism-perl \
    libfile-which-perl \
    libflac8 \
    libfontconfig1 \
    libfontenc1 \
    libfreetype6 \
    libfribidi0 \
    libgc1c2 \
    libgcc-7-dev \
    libgcc1 \
    libgcrypt20 \
    libgd3 \
    libgdbm-compat4 \
    libgdbm5 \
    libgdk-pixbuf2.0-0 \
    libgdk-pixbuf2.0-common \
    libgif7 \
    libgirepository-1.0-1 \
    libgl1 \
    libgl1-mesa-dri \
    libgl1-mesa-glx \
    libglapi-mesa \
    libglib2.0-0 \
    libglvnd0 \
    libglx-mesa0 \
    libglx0 \
    libgmp10 \
    libgnutls-openssl27 \
    libgnutls30 \
    libgomp1 \
    libgpg-error0 \
    libgphoto2-6 \
    libgphoto2-port12 \
    libgraphite2-3 \
    libgsasl7 \
    libgssapi-krb5-2 \
    libgssapi3-heimdal \
    libgstreamer-plugins-base1.0-0 \
    libgstreamer1.0-0 \
    libgtk2.0-0 \
    libgtk2.0-common \
    libharfbuzz0b \
    libhcrypto4-heimdal \
    libheimbase1-heimdal \
    libheimntlm0-heimdal \
    libhogweed4 \
    libhx509-5-heimdal \
    libice6 \
    libicu60 \
    libidn11 \
    libidn2-0 \
    libisl19 \
    libitm1 \
    libjbig0 \
    libjpeg-turbo8 \
    libjpeg8 \
    libk5crypto3 \
    libkeyutils1 \
    libkrb5-26-heimdal \
    libkrb5-3 \
    libkrb5support0 \
    libksba8 \
    libkyotocabinet16v5 \
    liblcms2-2 \
    libldap-2.4-2 \
    libldap-common \
    libllvm9 \
    liblsan0 \
    libltdl7 \
    liblz4-1 \
    liblzma5 \
    liblzo2-2 \
    libmagic-mgc \
    libmagic1 \
    libmailutils5 \
    libmount1 \
    libmpc3 \
    libmpdec2 \
    libmpfr6 \
    libmpg123-0 \
    libmpx2 \
    libmysqlclient20 \
    libncurses5 \
    libncursesw5 \
    libnettle6 \
    libnghttp2-14 \
    libnpth0 \
    libnspr4 \
    libnss3 \
    libntlm0 \
    libogg0 \
    libopenal-data \
    libopenal1 \
    liborc-0.4-0 \
    libp11-kit0 \
    libpam-modules \
    libpam-modules-bin \
    libpam-runtime \
    libpam0g \
    libpango-1.0-0 \
    libpangocairo-1.0-0 \
    libpangoft2-1.0-0 \
    libpcap0.8 \
    libpciaccess0 \
    libpcre3 \
    libpcsclite1 \
    libperl5.26 \
    libpipeline1 \
    libpixman-1-0 \
    libpng16-16 \
    libpopt0 \
    libprocps6 \
    libpsl5 \
    libpulse0 \
    libpython-stdlib \
    libpython2.7 \
    libpython2.7-minimal \
    libpython2.7-stdlib \
    libpython3-stdlib \
    libpython3.6-minimal \
    libpython3.6-stdlib \
    libquadmath0 \
    libreadline7 \
    libroken18-heimdal \
    librsvg2-2 \
    librsvg2-common \
    librtmp1 \
    libsasl2-2 \
    libsasl2-modules-db \
    libseccomp2 \
    libselinux1 \
    libsemanage-common \
    libsemanage1 \
    libsensors4 \
    libsepol1 \
    libserf-1-1 \
    libsigsegv2 \
    libsm6 \
    libsmartcols1 \
    libsndfile1 \
    libsndio6.1 \
    libsqlite3-0 \
    libss2 \
    libssl1.0.0 \
    libssl1.1 \
    libstdc++-7-dev \
    libstdc++6 \
    libsvn1 \
    libsystemd0 \
    libtasn1-6 \
    libthai-data \
    libthai0 \
    libtiff5 \
    libtimedate-perl \
    libtinfo5 \
    libtool \
    libtsan0 \
    libubsan0 \
    libudev1 \
    libunistring2 \
    libusb-1.0-0 \
    libuuid1 \
    libvorbis0a \
    libvorbisenc2 \
    libwebp6 \
    libwind0-heimdal \
    libwine \
    libwrap0 \
    libx11-6 \
    libx11-data \
    libx11-xcb1 \
    libx32asan4 \
    libx32atomic1 \
    libx32cilkrts5 \
    libx32gcc-7-dev \
    libx32gcc1 \
    libx32gomp1 \
    libx32itm1 \
    libx32quadmath0 \
    libx32stdc++-7-dev \
    libx32stdc++6 \
    libx32ubsan0 \
    libxau6 \
    libxaw7 \
    libxcb-dri2-0 \
    libxcb-dri3-0 \
    libxcb-glx0 \
    libxcb-present0 \
    libxcb-render0 \
    libxcb-shape0 \
    libxcb-shm0 \
    libxcb-sync1 \
    libxcb1 \
    libxcomposite1 \
    libxcursor1 \
    libxdamage1 \
    libxdmcp6 \
    libxext6 \
    libxfixes3 \
    libxfont2 \
    libxft2 \
    libxi6 \
    libxinerama1 \
    libxkbfile1 \
    libxml2 \
    libxml2-utils \
    libxmu6 \
    libxmuu1 \
    libxpm4 \
    libxrandr2 \
    libxrender1 \
    libxshmfence1 \
    libxt6 \
    libxtst6 \
    libxv1 \
    libxxf86dga1 \
    libxxf86vm1 \
    libzstd1 \
    linux-libc-dev \
    login \
    lsb-base \
    lsb-release \
    lsof \
    lzma \
    m4 \
    mailutils \
    mailutils-common \
    make \
    man-db \
    mawk \
    mime-support \
    mount \
    multiarch-support \
    mysql-common \
    ncurses-base \
    ncurses-bin \
    ocl-icd-libopencl1 \
    openjdk-8-jre \
    openjdk-8-jre-headless \
    openssh-client \
    openssl \
    passwd \
    patch \
    patchutils \
    perl \
    perl-base \
    perl-modules-5.26 \
    pinentry-curses \
    po-debconf \
    procmail \
    procps \
    python \
    python-apt-common \
    python-minimal \
    python-pip \
    python-pip-whl \
    python-pkg-resources \
    python-setuptools \
    python2.7 \
    python2.7-minimal \
    python3 \
    python3-apt \
    python3-dbus \
    python3-gi \
    python3-minimal \
    python3-software-properties \
    python3.6 \
    python3.6-minimal \
    readline-common \
    rsync \
    sed \
    sensible-utils \
    shared-mime-info \
    software-properties-common \
    ssmtp \
    subversion \
    sysvinit-utils \
    tar \
    time \
    ubuntu-keyring \
    ubuntu-mono \
    ucf \
    unzip \
    util-linux \
    wget \
    wine-stable \
    wine32 \
    x11-common \
    x11-utils \
    x11-xkb-utils \
    xauth \
    xkb-data \
    xserver-common \
    xvfb \
    xz-utils \
    zip \
    zlib1g \
    zlib1g-dev \
    libssl-dev \
    libwxgtk3.0-dev

# prepare gosu
ENV GOSU_VERSION 1.14
RUN set -eux; \
# save list of currently installed packages for later so we can clean up
    savedAptMark="$(apt-mark showmanual)"; \
    apt-get update; \
    apt-get install -y --no-install-recommends ca-certificates wget; \
    if ! command -v gpg; then \
        apt-get install -y --no-install-recommends gnupg2 dirmngr; \
    elif gpg --version | grep -q '^gpg (GnuPG) 1\.'; then \
# "This package provides support for HKPS keyservers." (GnuPG 1.x only)
        apt-get install -y --no-install-recommends gnupg-curl; \
    fi; \
    rm -rf /var/lib/apt/lists/*; \
    \
    dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
    wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
    wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
    \
# verify the signature
    export GNUPGHOME="$(mktemp -d)"; \
    gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
    gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
    command -v gpgconf && gpgconf --kill all || :; \
    rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
    \
# clean up fetch dependencies
    apt-mark auto '.*' > /dev/null; \
    [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
    apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
    \
    chmod +x /usr/local/bin/gosu; \
# verify that the binary works
    gosu --version; \
    gosu nobody true

# create entrypoint
RUN echo "#!/bin/bash" > /usr/local/bin/entrypoint.sh && \
    echo "USER_ID=\${LOCAL_USER_ID:-9001}" >> /usr/local/bin/entrypoint.sh && \
    echo "echo \"Starting with UID : \$USER_ID\"" >> /usr/local/bin/entrypoint.sh && \
    echo "useradd --shell /bin/bash -u \$USER_ID -o -c \"\" -m sdtv" >> /usr/local/bin/entrypoint.sh && \ 
    echo "export HOME=/home/sdtv" >> /usr/local/bin/entrypoint.sh && \ 
    echo "exec /usr/local/bin/gosu sdtv \"\$@\"" >> /usr/local/bin/entrypoint.sh && \
    chmod a+x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

CMD ["/bin/bash"]

相关内容