I am newbie to docker and trying to explore multistage build. I want to run a specific stage on docker docker build -t build-stage-tag --target build
I expect it to run the following stages dependencies --> compile --> build
and skip the test
. But it so happens that it runs the test stage as well.
Let me know if my understanding of multistage build --target
is wrong or there is some error in my docker file.
What I want to do is run the build
stage without running the test
and vice-versa.
This is how my Dockerfile looks :
# Pull base image
FROM openjdk:8u171 as dependencies
# Install Scala
## Piping curl directly in tar
// do some stuff
# Copy source into container
COPY . /usr/src/app
FROM dependencies as compile
WORKDIR /usr/src/app
# Test and build the jar in the same step to save time
RUN sbt -Dsbt.log.noformat=true compile
RUN sbt -Dsbt.log.noformat=true assembly
FROM compile as test
WORKDIR /usr/src/app
RUN sbt -Dsbt.log.noformat=true -Dtest_db_user=root -Dtest_db_password=password -Dtest_db_host=localhost coverage test coverageReport
FROM compile as build
# Define working directory
WORKDIR /root
COPY --from=compile /usr/src/push/target/scala-2.12/app-assembly-?*.?*.?*.jar ./push.jar
COPY --from=compile /usr/src/push/config/jvm.config ./jvm.config
COPY --from=compile /usr/src/push/entrypoint.sh /bin/entrypoint.sh
RUN chmod +x /bin/entrypoint.sh
ENTRYPOINT ["/bin/entrypoint.sh"]
CMD ["docker", "blah"]