Home > Back-end >  how to set docker image name as a file name it creates while building
how to set docker image name as a file name it creates while building

Time:06-25

So i want to set the docker image name as a file it creates. the stages inside the dockerfile are: set new version for pom.xml, compile, package all using mvn. i want to set the docker image name as the artifact the build creates Example: my-app-1.0.1

FROM maven:3-jdk-8-alpine AS build
ADD . /my-app
WORKDIR /my-app
RUN mvn versions:set -DnewVersion="1.0.1"
RUN mvn compile
RUN mvn package


FROM openjdk:8-jdk-alpine
COPY --from=build /my-app/target/my-app-1.0.1.jar my-app-1.0.1.jar
ENTRYPOINT ["java" "-cp" "my-app-1.0.1.jar" "com.mycompany.app.App"]

Thanks!

CodePudding user response:

look at docker build usage

You can specify a repository and tag at which to save the new image if the build succeeds:

$ docker build -t shykes/myapp:1.0.2

CodePudding user response:

So as Thorbjørn Ravn, Andersen and Max advised I changed my approach. i set it outside and put it right with the image build command. Thanks for the help everyone!

  • Related