lw0
lw0

Reputation: 199

Issue Running Docker Image

I have a test web application that I can run locally on localhost:8080. I build my application with maven:

mvn clean install -U

I run the application with the following maven command:

mvn org.codehaus.mojo:tomcat-maven-plugin:run

Then I can hit localhost url: http://localhost:8080/pokemon/healthcheck This is a simple test app that I want to dockarize just for a learning experience. I was able to run the python "Hello World" example, so i think i have everything installed in right places. My Dockerfile has the following:

FROM tomcat:alpine
RUN ["/bin/rm", "-fr", "/usr/local/tomcat/webapps/ROOT"]
RUN ["/bin/mkdir", "/var/log/tomcat8/"]
COPY target/pokemon.war /usr/local/tomcat/webapps/pokemon.war

Then I stop my locally running localhost, I assume I need to do that, and then I build the image with the following command:

docker build -t pokesheets .

Then I try running it with this command:

docker run -it pokesheets:latest

The log looks good to me, I see the message in the log that the service has started. The container is running, I can see it. But I cannot get to http://localhost:8080/pokemon/healthcheck. So I tried running the docker image with the following as well:

    docker run -it -p 8080:8080 pokesheets:latest
    docker run -d --name pokesheets -p 8090:8090 -p 8091:8091 pokesheets:latest
    docker run --rm -p 8080:8080 pokesheets:latest
    docker container run -d --name pokesheets -p 8080:8080 pokesheets:latest

I have a suspicion that maybe there is something very basic that I'm not aware of. I would very much appreciate input from someone who has some experience with the docker and could shed light on the issue.

Upvotes: 0

Views: 129

Answers (1)

Jesus Galvan
Jesus Galvan

Reputation: 576

You are not actually running the server inside the Docker container.

You build it and copy files into it, but you are not starting the server.

Use the ENTRYPOINT instruction.

Edit:

Tomcat official Docker image repo specifies to use the CMD instruction and also utilizes the :8888 port.

CMD ["catalina.sh", "run"]

Edit 2:

Build image: docker build -t pokesheets .

FROM tomcat:alpine

RUN ["/bin/rm", "-fr", "/usr/local/tomcat/webapps/ROOT"]
RUN ["/bin/mkdir", "/var/log/tomcat8/"]
ADD target/pokemon.war /usr/local/tomcat/webapps/pokemon.war

EXPOSE 8080

CMD ["catalina.sh", "run"]

Run container

docker run -it -p 80:8080 pokesheets:latest

Visit http://localhost:8080/pokemon/healthcheck

Upvotes: 1

Related Questions