0

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.

4
  • Have you expose the port in your Dockerfile? Look for stackoverflow.com/questions/35414479/… Commented Jan 9, 2020 at 6:48
  • @NIravModi EXPOSE instruction is just for documentation purposes, doesn't have any functionality. From docs : The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. Commented Jan 9, 2020 at 6:51
  • I agree with you @leopal Commented Jan 9, 2020 at 6:52
  • I did take a look at the EXPOSE earlier, but it didn't look like this is something I'd need @NIravModi. Commented Jan 9, 2020 at 17:13

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

Would I need both, the ENTRYPOINT and the above CMD?
No, you would most likely only use one. Stick to the official recommendation from Tomcat image repository, which is the CMD. Unless you had a specific reason to use the other.
I added CMD into the Dockerfile, remover old image, made a new one and tried running it with 'docker run -it -p 8080:8080 pokesheets:latest', but still getting page 'This site can’t be reached'.
Image official documentation binds the :8888 port to the :8080 host port. Did try like that? -p 8888:8080 and visit 8080 on your browser.
I just tried running it again with 8888:8080, then tried my link 8080, then with 8888, still no luck. The log does show the server is running: 'INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 17559 ms'
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.