0

Following docker image starts tomcat8 in a fresh ubuntu 16.04 in a virtualbox but doesnt in a docker container. Is this a problem with docker, tomcat or am I missing on something?

Dockerfile:

FROM ubuntu:16.04

RUN apt update

RUN apt install -y openjdk-8-jdk

RUN apt-get install -y tomcat8

CMD service tomcat8 start
ducci
  • 351
  • 1
  • 4
  • 15
  • Check this https://stackoverflow.com/questions/42218957/dockerfile-cmd-instruction-will-exit-the-container-just-after-running-it Seems that you have the same problem – Arturo Seijas Nov 30 '18 at 07:55
  • I also had a version of the file like this omitting the CMD command: FROM ubuntu:16.04 RUN apt update RUN apt install -y openjdk-8-jdk RUN apt-get install -y tomcat8 and then I build it like this: docker build -t tomcat . and started the container like this so I could have the bash inside of the container: docker run -p 8080:8080 -it tomcat inside I then run "service tomcat8 start" but it says it failed although it started as the logs at /var/logs/tomcat8/catalina.out stated. I could also browse to localhost:8080 with response from tomcat – ducci Dec 01 '18 at 11:47

1 Answers1

0

I assume that the image is built correctly (docker build command ends without errors)

While running the docker container just connect to it and check its logs:

docker logs <CONTAINER_ID> -f

You should see what happens there and why does tomcat fail to start. Maybe Java is not mapped correctly, maybe the ports are busy (unlikely but who knows).

And maybe tomcat starts correctly but you can't access it from outside because the 8080 port is not exposed / mapped (EXPOSE 8080 in docker file / -p 8080:8080 option while running a docker container)

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
  • actually it starts but it just says that it fails. I mapped -p 8080:8080 and could reach the site provided by tomcat. the problem here is that I cant stop it since it says that it fails at starting. logs are saying that it started fine – ducci Nov 30 '18 at 11:46
  • I also did a dockerfile omitting the cmd and then run the image with -it option to log into and run service tomcat8 start on terminal inside docker but ger same error – ducci Nov 30 '18 at 12:28