Working on OSX, zsh within iTerm2.
I have a .sh script to build a Docker container. It was originally being built using openjdk Alpine but I transitioned to Bullseye such that it works with M1 chips on Mac. I'm now running into an issue where these lines in the file don't run:
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
When running this I get the following error:
------
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]
I'm fairly new to Docker but I'm a bit confused as to why this is. With Alpine these RUN commands were apk
so I simply changed them to apt-get
to match Bullseye's package manager. Using apt
results in the same error. Have I done something wrong? I'm not even sure of the proper terminology here so apologies for ay errors. Here is the full Dockerfile:
# 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"]
If we try building from the following
Dockerfile
:It will fail with this error:
As you can see
apt-get
is attempting to prompt for interactive input, but because it's not an interactive environment the command fails. We need to tellapt-get
to install without prompting by adding the-y
flag to theupgrade
command. Theinstall
command will need the same treatment:I've consolidated your multiple
apt-get install
commands into a single command (because that will generally be faster), but you can of course continue to use multiple commands if you wish.This
Dockerfile
builds without errors.