Reputation: 290
I have a Dockerfile which has the following content
# Build
FROM ${ECR_PREFIX}/maven:3.6.3-jdk-11 AS build
COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package
# Package
FROM ${ECR_PREFIX}/openjdk:11-jre-slim
COPY --from=build /home/app/target/application.jar application.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "application.jar"]
I tried to build this using
export PREFIX=${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com
docker build -t backend --build-arg ECR_PREFIX=$PREFIX .
but this would not work. I am really trying not to hard code the prefix especially ${AWS::AccountId} part of it because of various reasons.
Any pointers here?
Upvotes: 1
Views: 1635
Reputation: 158848
You have to explicitly declare the ARG
in your Dockerfile. If you use an ARG
value in a FROM
line then the ARG
needs to come before any FROM
. (Other ARG
s need to be repeated in each build stage that uses them.)
ARG REGISTRY=docker.io
FROM ${REGISTRY}/maven:3.6.3-jdk-11 AS build
REGISTRY=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
docker build \
-t $REGISTRY/backend:$(git rev-parse HEAD) \
--build-arg REGISTRY=$REGISTRY \
.
Upvotes: 3