Hi everyone,
I’m running a Tomcat 8.5 application inside a Docker container on my VPS, but I’m encountering an issue with a 404 error when accessing an endpoint that should be served by a deployed WAR file.
Here’s my setup:
Docker Compose file:
MySQL container (mysql-db)
Tomcat container (tomcat-app)
Both connected via a custom network bridge
Tomcat Dockerfile:
Multi-stage build that uses openjdk:8 for building the WAR file with Gradle
Then uses the mdelapenya/tomcat-mysql:7.0.77 image to run Tomcat 7.0.77 (I have tried with Tomcat 8.5 in docker-compose.yml)
WAR file: brain.war deployed to /opt/apache-tomcat-7.0.77/webapps/
The services are up and running without issues. I can access the Tomcat home page at http://vps111.host.al:8080, but when I try to access my app endpoint http://vps111.host.al:8080/facts/list, I get a 404 error.
Here’s what I’ve done so far:
Confirmed the WAR file was copied into /webapps/ folder.
Checked logs, and Tomcat starts successfully without deployment errors.
Verified URL mappings in Grails (UrlMappings.groovy) are correct.
Set environment variables in the container for MySQL datasource configuration.
Despite everything looking correct, the endpoint always returns a 404. Can anyone help troubleshoot why my application isn’t serving content on this endpoint?
Why should Tomcat load the brain.war file? As far as I know the fle should be called ROOT.war. If you have any setting that makes your file loadable, please, share.
Thank you for your input! You are right that Tomcat defaults to loading a ROOT.war file for deployment at the root context. However, Tomcat can also load WAR files with different names, and it will deploy them under context paths matching the file name.
For example, my brain.war file is deployed at /brain context. If you place any myapp.war file in Tomcat’s webapps directory, Tomcat will deploy it under /myapp.
If you specifically want to deploy the application to the root context (i.e., /), you would need to either:
Rename the brain.war file to ROOT.war before deployment, or
Configure the context.xml to map the application to /.
In my setup, I prefer keeping the WAR name brain.war as I want to use the /brain context. Let me know if you’d like more details on this!
I knew it could be configured, that is what I asked for it. If that is correct, maybe there is something with the image itself which supports an outdated Tomcat version. You could try the official repo or contact the image maintainer.
For now, I see nothing that indicates it is a Docker issue. Isn’t there some kind of Tomcat debug log you could enable to show what configuration files were applied and what rule loaded the webpage giving you 404?
I’m currently using a multi-stage Docker build to handle the WAR file deployment. Here’s the relevant part of the Dockerfile:
# First stage: build the application
FROM openjdk:8 AS build
WORKDIR /app
# Copy the source code to the container
COPY . .
# Run the build command to create the WAR file
RUN ./gradlew assemble
# Second stage: setup Tomcat with the built WAR file
FROM mdelapenya/tomcat-mysql:8.5
# Set the working directory to the Tomcat webapps directory
WORKDIR /usr/local/tomcat/webapps
# Copy the WAR file from the build stage to the Tomcat webapps directory
COPY --from=build /app/build/libs/brain.war .
# Expose ports
EXPOSE 8080
EXPOSE 3306
# Adjust the entry point to specify the full path to catalina.sh
ENTRYPOINT ["/usr/local/tomcat/bin/catalina.sh", "run"]
As you can see, I’m placing the brain.war file directly into the /usr/local/tomcat/webapps directory. If you think that’s incorrect or there’s something else I might need to configure, I’d love to hear your feedback!
As you can see, I’m placing the brain.war file directly into the /usr/local/tomcat/webapps directory. If you think that’s incorrect or there’s something else I might need to configure, I’d love to hear your feedback!
As for logging, I haven’t enabled any specific debug options in Tomcat yet. Would you suggest any particular settings or logs to look into for more detailed information?
I’m not sure why you quoted “backticks” from @bluepuma77’s answer, but I added it for you this time.
Next time, please, format your post according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.
You should probably:
A. change the mysql db password
B. Use variable interpolation or env_file instead of writing the password in the compose file
C. If the database is not meant for external use, only by your other containers, unmap the ports to disallow external access
Since you have no problem with Docker, but the application inside, it isn’t really a Docker issue, so the compose and the dockerfile will not help much in this case, We could still help if you share the config file that makes you think it should map the url to the war file.
EDIT.: Your PM indicates you could not find the war file in the folder although you stated here the file was there. Let’s keep the conversation here so everyone can help. Also make sure you are using the same config or always point out when you changed the config as different config can have different errors and it is impossible to follow the issue without knowing which config caused it.
I think the problem may be with the image itself
But i have tried a couple of images but when i browse on this url :8080 they dont even show me the default tomcat
The thing that i want to do is to capture my service
So to use the ip of my server and then the url of my service
I have shared to you the Dockerfile and the docker-compose.yml file
What files do you want next
I even quoted your own message where you mentioned the filename. So I will not spend more time on asking for the same file, sorry. Maybe someone else would be able to comunicate more clearly if I failed.
And I still stand by my opinion that it is an application specific issue which should be discussed on a Java forum or with the image maintainer.
Additional note: this is not what containers are intended for. Their primary purpose is separation of concerns. You should use a Tomcat and a separate DB container, connect them with a Docker network. That way they are independent, no potential library difficulties, they can be independently upgraded.
And the image you have selected (link) seems to be already 7 years old, that’s really not the way to go.