Reputation: 1523
I'm trying to run my java app on a docker container. I'm using a tomcat server locally and it's working fine. I'm new to java/tomcat/docker so there's something I might be very well missing something very simple but I assumed just pointing my local war file to /usr/local/tomcat/webapps
would be enough.
Here is my docker-compose.yml
tomcat-dev:
image: tomcat:8.5.38
environment:
- TOMCAT_USERNAME=root
- TOMCAT_PASSWORD=root
ports:
- "8888:8080"
volumes:
- /target/npmanager.war:/usr/local/tomcat/webapps/npmanager.war
mysql-dev:
image: mysql:8.0.2
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: npmanagercd
volumes:
- /mysql-data:/var/lib/mysql
ports:
- "3308:3306"
I can see the npmanager.war
file in the webapps directory but I can't access my app. My localhost still shows me the tomcat page instead of the "Hello, World" I see when I run it from my local install of tomcat.
Is there something I'm missing about deploying war files on tomcat?
Upvotes: 3
Views: 3543
Reputation: 1523
Okay, so I finally got it working. I wanted to post this answer here if it would help anyone else, but in all honestly I'm not sure I completely understand it.
I had to create a separate Dockerfile for the tomcat image:
FROM tomcat:8.5.38
ADD ./target/npmanager.war /usr/local/tomcat/webapps/
CMD chmod +x /usr/local/tomcat/bin/catalina.sh
CMD ["catalina.sh", "run"]
And then build that image in the docker-compose.yml
version: '3'
services:
tomcat-dev:
build: .
environment:
TOMCAT_USERNAME: root
TOMCAT_PASSWORD: root
ports:
- "8888:8080"
mysql-dev:
image: mysql:8.0.2
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: npmanager
volumes:
- /mysql-data:/var/lib/mysql
ports:
- "3308:3306"
Upvotes: 1