无法 运行 Dockerfile "executor failed running" 中的 `apt-get` 命令

Unable to run `apt-get` commands in Dockerfile "executor failed running"

正在 OSX,iTerm2 中的 zsh。

我有一个 .sh 脚本来构建 Docker 容器。它最初是使用 openjdk Alpine 构建的,但我过渡到 Bullseye 以便它可以与 Mac 上的 M1 芯片一起使用。我现在 运行 遇到一个问题,文件中的这些行不 运行:

 18 # Install git as additional requirement
 19 RUN apt-get update && \
 20     apt-get upgrade  && \
 21     apt-get install git && \
 22     apt-get install bash

当 运行 执行此操作时,出现以下错误:

------
executor failed running [/bin/sh -c apt-get update &&     apt-get upgrade  &&     apt-get install bash]: exit code: 1
.
---------------------------------------------------------------------------
ERROR while building docker container!
---------------------------------------------------------------------------
USAGE:
docker/buildDocker.sh [TAG_NAME]

我是 Docker 的新手,但我有点困惑为什么会这样。对于 Alpine,这些 运行 命令是 apk 所以我只是将它们更改为 apt-get 以匹配 Bullseye 的包管理器。使用 apt 会导致相同的错误。我做错了什么吗?我什至不确定这里的正确术语,所以对错误表示歉意。这是完整的 Docker 文件:

# START GLOBAL DECLARATION
####################################################
ARG REPO_NAME_DEFAULT=[REDACTED]
ARG REPO_PORT_DEFAULT=8040
ARG SERVICE_ROOT_DIRECTORY_DEFAULT=/spring/
####################################################
# END GLOBAL DECLARATION
####################################################

####################################################
# Building environment (java & git)
####################################################
FROM openjdk:16-bullseye AS build-env-java
LABEL maintainer=[REDACTED]
LABEL stage=build-env

# Install git as additional requirement
RUN apt-get update && \
    apt-get upgrade  && \
    apt-get install git && \
    apt-get install bash

####################################################
# Building service
####################################################
FROM build-env-java AS [REDACTED]
LABEL maintainer=[REDACTED]
LABEL stage=build-contains-sources

# Fetch arguments from above
ARG REPO_NAME_DEFAULT
ARG SERVICE_ROOT_DIRECTORY_DEFAULT

# Declare environment variables
ENV REPO_NAME=${REPO_NAME_DEFAULT}
ENV SERVICE_DIRECTORY=$SERVICE_ROOT_DIRECTORY_DEFAULT$REPO_NAME

# Create directory for repo
RUN mkdir -p /git/${REPO_NAME}
WORKDIR /git/${REPO_NAME}
COPY . .
RUN cp settings/application-docker.properties settings/application-default.properties
# Build service in given directory
RUN bash ./build.sh $SERVICE_DIRECTORY

####################################################
# Runtime environment 4 [REDACTED]
####################################################
FROM openjdk:16-bullseye AS [REDACTED]
LABEL maintainer=[REDACTED]
LABEL stage=run

# Fetch arguments from above
ARG REPO_NAME_DEFAULT
ARG REPO_PORT_DEFAULT
ARG SERVICE_ROOT_DIRECTORY_DEFAULT

# Declare environment variables
ENV REPO_NAME=${REPO_NAME_DEFAULT}
ENV SERVICE_DIRECTORY=${SERVICE_ROOT_DIRECTORY_DEFAULT}${REPO_NAME}
ENV REPO_PORT=${REPO_PORT_DEFAULT}

# Install bash as additional requirement
RUN apt-get update && \
    apt-get upgrade  && \
    apt-get install bash

# Copy service from build container
RUN mkdir -p ${SERVICE_DIRECTORY}
WORKDIR ${SERVICE_DIRECTORY}
COPY --from=[REDACTED] ${SERVICE_DIRECTORY} ./

# Define repo port 
EXPOSE ${REPO_PORT}
ENTRYPOINT ["bash", "./run.sh"]

如果我们尝试从以下 Dockerfile 构建:

FROM openjdk:16-bullseye AS build-env-java

# Install git as additional requirement
RUN apt-get update && \
    apt-get upgrade  && \
    apt-get install git && \
    apt-get install bash

它将失败并出现以下错误:

[...]
After this operation, 15.4 kB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
The command '/bin/sh -c apt-get update &&     apt-get upgrade  &&     apt-get install git &&     apt-get install bash' returned a non-zero code: 1

如您所见,apt-get 正在尝试提示交互式输入,但由于它不是交互式环境,命令失败。我们需要通过将 -y 标志添加到 upgrade 命令来告诉 apt-get 安装而不提示。 install 命令需要同样的处理:

FROM openjdk:16-bullseye AS build-env-java

# Install git as additional requirement
RUN apt-get update && \
    apt-get -y upgrade  && \
    apt-get -y install git bash

我已将您的多个 apt-get install 命令合并为一个 单个命令(因为这通常会更快),但你可以 如果您愿意,当然可以继续使用多个命令。

Dockerfile 构建没有错误。