Docker Tomcat Error 404

Hello everyone,

I try to install tomcat with a war application on Docker by dockerfile.

My Dockerfile is on dir /root:

FROM tomcat:9.0-jdk8-corretto

MAINTAINER tennents

ADD HelloWorld.war /usr/local/tomcat/webapps/

CMD ["/usr/local/tomcat/bin/catalina.sh", "run"]

I build the images without errors with the command:

docker build -t mytomcat .

after run docker with the follow command:

docker run -itd -p 8080:8080 --name TomcatContainer mytomcat

The TomcatContainer is up and running but if I test the application via local browser received the follow error:
HTTP Status 404 – Not Found

Can you help me?

Thanks and regards,
Tennents23

Please, use code formatting as described in the below topic. I fixed your post.

How exactly are you trying to load the webapp from the browser? Since you haven’t shared the URL, we can’t tell if the error is normal or not. Based on what you shared it doesn’t look like a Docker issue, because your app is called HelloWorld.war but and if you want it to be accessible at http://localhost:8080/, as far as I know you need to copy it as ROOT.war. Otherwise you might need to map the application filename to a path in the URL if it doesn’t happen automatically.

Docker related suggestions

  • MAINTAINER i deprecated. The recommended way is using a LABEL
    LABEL maintainer=tennents
    
  • I would use COPY instead of ADD, because ADD can also extract files automatically or download it directly from a website. I use COPY to copy files and RUN curl ... to download files so I know exactly when and how it will be extracted.
  • If you want to copy HelloWorld.war as ROOT.war you can use this line:
    COPY HelloWorld.war /usr/local/tomcat/webapps/ROOT.war
    

Hi Rimelek,

thanks for fixed my post.
I change my Dockerfile with your suggestions and now the web application running correctly.

Thanks a lot,
Tennents23