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.

lw0
  • 199
  • 2
  • 10
  • Have you expose the port in your Dockerfile? Look for https://stackoverflow.com/questions/35414479/docker-ports-are-not-exposed – NIrav Modi Jan 09 '20 at 06:48
  • @NIravModi `EXPOSE` instruction is just for documentation purposes, doesn't have any functionality. From [docs](https://docs.docker.com/engine/reference/builder/#expose) : 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. – leopal Jan 09 '20 at 06:51
  • I agree with you @leopal – NIrav Modi Jan 09 '20 at 06:52
  • I did take a look at the EXPOSE earlier, but it didn't look like this is something I'd need @NIravModi. – lw0 Jan 09 '20 at 17:13

1 Answers1

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

Jesus Galvan
  • 572
  • 3
  • 9
  • Would I need both, the ENTRYPOINT and the above CMD? – lw0 Jan 09 '20 at 17:18
  • 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. – Jesus Galvan Jan 09 '20 at 17:32
  • 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'. – lw0 Jan 09 '20 at 17:36
  • [Image official documentation](https://hub.docker.com/_/tomcat) binds the `:8888` port to the `:8080` host port. Did try like that? `-p 8888:8080` and visit `8080` on your browser. – Jesus Galvan Jan 09 '20 at 17:39
  • 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' – lw0 Jan 09 '20 at 17:46
  • @lw0 Added an updated Dockerfile and additional commands to 'Edit 2'. Try that. – Jesus Galvan Jan 09 '20 at 17:58
  • Wow! that made the difference, although not for 8080 port - With the EDIT 2 I can reach the page with http://localhost/pokemon/healthcheck , but not with 8080. But you know, that's a win nonetheless! Thank you! – lw0 Jan 09 '20 at 18:09