Deploy tomcat on ubuntu image

I have download docker Ubuntu image. On top of Ubuntu image, i want to copy my local tomcat, java, other dependencies into a image with tag as “miniimagesvideos”. Refer the below mentioned Dockerfile.

from ubuntu
#RUN mkdir /mnt/
RUN mkdir /mnt/opt/
RUN mkdir /mnt/opt/apache-tomcat-9.0.5/
COPY /mnt/opt/ /mnt/opt/
ENV CATALINA_HOME /mnt/opt/apache-tomcat-9.0.5
ENV PATH /mnt/opt/java/jdk-10.0.1/bin:$PATH
ENV GOOGLE_APPLICATION_CREDENTIALS /mnt/opt/apache-tomcat-9.0.5/webapps/compression/WEB-INF/classes/ocrlib/My_First_Project_1524e734fcd9.json
EXPOSE 80 443
CMD /mnt/opt/apache-tomcat-9.0.5/bin/ run

Please note my java, tomcat and other dependences are inside /mnt/opt/ directory. I have run the following command to build.

docker build -t miniimagesvideos .
[+] Building 581.9s (9/9) FINISHED
[internal] load build definition from Dockerfile 0.0s
transferring dockerfile: 555B 0.0s
[internal] load .dockerignore 0.1s
transferring context: 2B 0.0s
[internal] load metadata for Docker 0.0s
CACHED [1/4] FROM Docker 0.0s
[internal] load build context 182.6s
transferring context: 19.86GB 182.2s
[2/4] RUN mkdir /mnt/opt/ 0.7s
[3/4] RUN mkdir /mnt/opt/apache-tomcat-9.0.5/ 1.1s
[4/4] COPY /mnt/opt/ /mnt/opt/ 182.9s
exporting to image 215.8s
exporting layers 215.8s
writing image sha256:73a333dc5f1bcf9265082c5aafb2f3743cd8a7e420713d768a12d 0.0s
naming to docker io/library/miniimagesvideos 0.0s

After build i am trying to run the container with the following command.

docker run -it -p 80:80 miniimagesvideos
Using CATALINA_BASE: /mnt/opt/apache-tomcat-9.0.5
Using CATALINA_HOME: /mnt/opt/apache-tomcat-9.0.5
Using CATALINA_TMPDIR: /mnt/opt/apache-tomcat-9.0.5/temp
Using JRE_HOME: /mnt/opt/java/jdk-10.0.1
Using CLASSPATH: /mnt/opt/apache-tomcat-9.0.5/bin/bootstrap.jar:/mnt/opt/apache-tomcat-9.0.5/bin/tomcat-juli.jar
Tomcat started.

Refer the output after the docker run command. It gives the output that tomcat has started. However, when i look at the ps of docker, i cannot see anything.

docker ps

I cannot access anything from the URL
What is missing? I am new to docker, so may be i am missing something. I have tried to run the container with the option --network host

When you use run , the Tomcat server starts in the background, which might cause your Docker container to stop. To prevent this, you could use run instead, which will run the Tomcat server in the foreground.

1 Like

This was so helpful. Thanks a lot. I was struggling from last 2 days. It seems to be working. I will do some further testing.
Another query: How can i get handle on the command prompt of container. I want to monitor logs, verify file system etc.

Glad it helped, you can use following command to get handle on command prompt of container

docker exec -it <container_id> sh

1 Like