hello community
I installed tomcat in a docker container using Docker Desktop.
All works fine seemingly. I get the output from the tomcat log that the sever has been started successfully on port 8080. The container view in docker desktop shows that the conainer and app is up and running.
But I cannot connect tomcat via browser.
I mapped 12345:8080
and cannot access it via none of the following urls
localhost:12345
127.0.1:12345
172.17.0.2:12345
192.168.99.100:12345
the last two ip addresses were suggested in other posts.
totally clueless after hours of searching for a solution.
If anybody could help …
Yep, I see it now. I didn’t see it when I typed my response.
Interesting: even though the tag is not listed on Dockerhub, it can be pulled.
Please be aware that it’s not advised to use old images, as they potentially have many vulnerabilities. Also make sure you pick a version that is still supported, so it still receives security fixes.
The image description does not mention how to extend the image.
Are you sure extracting sample.war to /usr/local/tomcat/webapps is correct?
Apart from that the Syntax of your Dockerfile, build command and the command to start the container look good to me.
You might want to investigate error messages in the container logs docker logs ${container id or name}. Use docker ps -a to get the list of running and exited containers.
If the container is running and the logs indicate no errors, you should be able to access tomcat using the url http://localhost:12345.
it should be … tomcat does auto deploy when a new war file is found in the webapps directory.
at least there is no error when running the build about non existing directories or files.
I will investigate into the logs and see what I find.
I suspect that it may somehow be windows related. I checked on the microsoft docker support site and they seem to be aware of a docker access problem but they only suggest to look into the logs
anyway, thank you very much for your effort.
at least the general approach is correct which I wasn’t 100% sure about.
It has been a couple of years since I dealt with tomcat - since a couple of years almost every java project I have seen uses spring boot with the embedded tomcat.
I am aware of the auto deployment. The ADD instruction might extract the war-file (after all it’s a zip file). I am not sure how tomcat handles it.
Note: the COPY instruction would copy the war file as is, the ADD instruction extracts archives.
You cannot connect or you cannot access the webapp? What does the browser return? HTTP 404 or connection refused or something else?
Also I am wondering, is it the first you have to install a tomcat app or it is just the first you try in a container?
I totally agree with @meyay regarding the ADD instruction, however, I tried a war file and it wasn’t extracted, but I would still prefer to use the COPY instruction because it is much clearer what it does.
If you want to install a tomcat webapp, you need to configure tomcat to find it and map the URL and the applications. If you have one app that you want to access without a subpath in the URL and without tomcat configuration, you need to call it ROOT.war. Related topic:
I’m getting connection refused, not 404. as if something is blocking access. That’s what made me think of some windows issue, maybe some firewall option but I checked the browser’s access rights and they are granted…
you are right, for a root url there would have to be a Root.war but I’m using the apps’s name … but as said, it’s not a 404.
I tried as well to ping but it says host(!) not found … totally weird.
btw, I tried both ADD and COPY … no change.
Anyways, I currently don’t have the time to investigate deeper into this. microsoft support has some sugggestions regarding logs but I haven’t figured that out quite yet as their doc is rather poor.
I highly appreciate your comments and effort, at least the basic approach seems to be correct.
I got it fixed but I do not understand why/how
I had some virtual hosts defined in my windows hosts file. I commented them and built the container anew and now it is working.
It was just a wild guess as I some time ago had the issue that my xampp installation was not found under localhost/ anymore since I made the entries in the hosts file.
The two instructions often do the same, but ADD does more worked differently at different times of the history of Docker (not experienced, just heard). In this case it didn’t matter, but if I could decide, I would even remove ADD from Docker’s source code or replace it with a better designed FETCH or something with an optional --unarchive flag, so I still recommend using COPY.
I don’t understand that either. Unless you also commented out some “Listen” directive, commenting out virtual hosts should not have made a difference. It works for you so it doesn’t matter anymore, but if you ever find out why it helped, please come back and share