0

I want to Containerize a web application which is a WAR file along with Postgres as database and Tomcat as Server.

What will be the procedure to do that?

I am using the following dockerfile:

FROM tomcat:8-jre8 MAINTAINER lpradel 
RUN echo "export JAVA_OPTS=\"-Dapp.env=staging\"" > /usr/local/tomcat/bin/setenv.sh
COPY ./application.war /usr/local/tomcat/webapps/staging.war
CMD ["catalina.sh", "run"]
Ayushya
  • 9,599
  • 6
  • 41
  • 57
Shahid ali Khan
  • 305
  • 2
  • 4
  • 11

2 Answers2

0

Write a dockerfile for each application. E.g: Base a dockerfile on a tomcat server docker image, copy over your warfile and start the tomcat in the cmd part of the dockerfile.

For postgres you should be able to use an existing image.

herm
  • 14,613
  • 7
  • 41
  • 62
  • I tried the same process but after running the container the specific URL is not running. – Shahid ali Khan Jul 18 '17 at 07:08
  • Then post your dockerfile please so that people can help you. – herm Jul 18 '17 at 07:12
  • The general structure seems fine. Though I would not be sure that the folder you copy your war to is the right folder (usr/local..). Make sure that the filesystem in the container is structured the way you assume. After you started a container you can do docker inspect containername/id to see the logs of the container. That should help you find the error. You can also do that for containers that stopped – herm Jul 18 '17 at 08:50
  • * don't do docker inspect containername but docker logs containername. Sorry I confused the commands – herm Jul 19 '17 at 08:38
0

Updated answer:

The dockerfile you are using is correct. This should prepare a tomcat image which has the web application you want. However you may want to connect that tomcat container with postgress container.

Easier way to connect multiple containers would be to use a docker-compose file. To use docker-compose, refer to docker-compose#build.

Original answer You can mount your war file in tomcat container at /usr/local/tomcat/webapps/name_of_your_file.war inside container. This will enable the war file to be automatically deployed by tomcat container.

By the way, I am doing the similar process and using mysql database. Taking a look at the my deployment file might be helpful to you.

Ayushya
  • 9,599
  • 6
  • 41
  • 57
  • @ShahidaliKhan It would be helpful to others too if you posted the dockerfile in your question. As its difficult to browse answers and look for details of the question. – Ayushya Jul 18 '17 at 08:36
  • I am using the following deployment file. `FROM tomcat:8-jre8 MAINTAINER lpradel RUN echo "export JAVA_OPTS=\"-Dapp.env=staging\"" > /usr/local/tomcat/bin/setenv.sh COPY ./application.war /usr/local/tomcat/webapps/staging.war CMD ["catalina.sh", "run"]` – Shahid ali Khan Jul 18 '17 at 08:36
  • Deployment file I mentioned about, is a bash script which sets up the necessary environment, like downloading database files, and extracting other files. While [`docker-compose.yml`](https://github.com/reactome/container/blob/develop/docker-compose.yml) is used to build containers and run them. – Ayushya Aug 01 '17 at 05:24