skip to Main Content

Currently I am running windows with docker for windows installed.
I have made a java application in Spring Boot that I want to build an image of and run in a docker container.

What am I doing wrong?
When I run the bellow and can see in my cmd prompt that the application starts and run. But there is no image in in docker and nothing running there.

#
# Build stage
#
FROM maven:3.8.4-openjdk-17 AS build
COPY src /test/src
COPY pom.xml /test
#RUN mvn -f /test/pom.xml clean package
RUN mvn -f /test/pom.xml clean package

#
# Package stage
#
FROM openjdk:17-alpine
COPY --from=build /test/target/test-0.0.1-SNAPSHOT.jar /usr/local/lib/test.jar

ENTRYPOINT ["java","-jar","/usr/local/lib/test.jar"]

What am I missing?

I have the application in a folder /test and the Dockerfile is also under /test. I go to this location in the cmd prompt and enter:

docker build -t testapp .

3

Answers


  1. docker build will only build docker image
    if you want to run the image in your docker try running the command

    docker run  testapp
    

    docker build builds a new image from the source code.

    docker create creates a writeable container from the image and prepares it for running.

    docker run creates the container (same as docker create) and runs it.

    Login or Signup to reply.
  2. The command you are running, docker build -t testapp ., only creates the docker image that you can check with the command someone stated in the comments : docker images -a.

    To run the image in a docker container you must use the run command : docker run testapp. Then you will see the container in the Docker app.

    Login or Signup to reply.
  3. I was doing everything correct except for that when I thought the image was ready/built I run test of my java application that looked as the application had started.

    By setting <maven.test.skip>true</maven.test.skip> I skipped the test and the build was finished. I got the image which I now can start. Thank you all for your question and assistance.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search