Tomcat on Docker can't be found - docker

I am trying to run Tomcat on Docker but even though my container is running, when I go to localhost I get a not found error as it is possible to see in the image below
I used the command docker pull tomcat to get Tomcat and then in order to start my container I runned the command docker run -p 8080:8080 -dit tomcat.
Why isn't Tomcat being found when I access localhost:8080?
I edited the file tomcat-users.xml adding the following code
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,admin"/>
and the file context.xml
<Context antiResourceLocking="false" privileged="true" >
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
and server.xml to change to port 8888
<Connector port="8888" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
but still giving the error

That's exactly what should happen when the tomcat Docker image is used. See the "How to use this image." section of the Docker Hub page. In order to start the manager application that it sounds like you're looking for, some configuration is required.

Related

Docker Jetty Webserver: only showing war contents instead of running server

maybe someone can help me with my problem:
I've got a running docker and deployed a .war file to my jetty webapps folder at (/var/lib/jett/webapps)
This exact .war file is running at other machines, but the one i'm currently working on wont execute the .war/ start the webserver.
When i open a browser and navigate to myIP:Portnumber/myWarFile jetty only shows me the files inside the .war, but a cant access the actual website.
Is there any configuration that i might have missed?
My Docker config for jetty looks like this:
docker run --name zynq --restart always -d -p 9999:8080 -v /var/lib/jetty/webapps:/var/lib/jetty/webapps -v /home/sven/Desktop/jetty:/home/sven/Desktop/jetty jetty
Last lines of verbose output when starting the docker jetty container:
ty/jetty-0_0_0_0-8080-MESSE072_war-_MESSE072-any-3951420110201373021/webapp/WEB-INF/lib/vaadin-split-layout-4.1.0.jar!/META-INF/resources],AVAILABLE}{/var/lib/jetty/webapps/MESSE072.war}
2022-09-12 08:58:13.501:INFO :oejs.AbstractConnector:main: Started ServerConnector#dfb0738{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2022-09-12 08:58:13.509:INFO :oejs.Server:main: Started Server#184cf7cf{STARTING}[11.0.11,sto=5000] #1413ms
Any clue, why this might not work?
Thanks alot for any ideas!

Pseudo-distributed hadoop dfs in docker. Trouble connecting from local machine to dfs

I've set up docker file that starts up a pseudo-distributed dfs when it runs. My goal is to test my spark app to see it is writing to the dfs correctly. But for starters, I'm just trying to run this command from local terminal to ensure I can connect to the dfs in the docker container from my local machine:
hdfs dfs -ls hdfs://localhost:9000/
When my core-site.xml looked like this:
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
I would constantly get this error when I tried to connect via local hdfs-client:
ls: End of File Exception between local host is: "MacBook-Pro.local/192.168.0.4"; destination host is: "localhost":9000; : java.io.EOFException; For more details see: http://wiki.apache.org/hadoop/EOFException
When I change the core-site.xml to look like this:
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://0.0.0.0:9000</value>
</property>
</configuration>
It worked fine and I was able to connect to the dfs from local machine.
I'm just wondering why.

How do I find my hadoop cluster run from docker?

I am trying to do an experiment to test different runtimes of algorithms using Hadoop with 3 nodes and pig installed. I found a docker image (fluddeni/hadoop-pig) that meets these needs and seemingly is running when checked with docker ps, but I can't find it on any of my ports. I am running my code on Windows and when I check where other docker images run (the docker-machine ip) on the port 9000, as indicated in my core-site.xml file I am getting no page found. Any ideas on where to find the master page for hadoop? Let me know if you need any more information!
Resources:
/usr/local/hadoop/etc/hadoop/core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://3b85d55c5080:9000</value>
</property>
</configuration>
command docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b85d55c5080 fluddeni/hadoop-pig "/etc/bootstrap.sh -…" 19 hours ago Up 2 seconds 2122/tcp, 8020/tcp, 8030-8033/tcp, 8040/tcp, 8042/tcp, 8088/tcp, 9000/tcp, 10020/tcp, 19888/tcp, 49707/tcp, 50010/tcp, 50020/tcp, 50070/tcp, 50075/tcp, 50090/tcp boring_ptolemy
did you expose the port as you expect?
docker run -p 9000:9000 <rest image details>
reference:
Publish or expose port (-p, --expose)
While port forwarding is one problem, another is the fact that that container ID is not consistent. You should use Docker service DNS names
Ideally, using Compose network bridges.
Then you would always refer to hdfs://namenode:9000, for example

How to enable https on a Tomee docker container?

I'm running a tomee(8.0.1) docker image version and I would like to enable ssl on it.
I have seen these topics:
https://mkyong.com/tomcat/how-to-configure-tomcat-to-support-ssl-or-https/
how to make java - tomee application HTTPS?
How to enable HTTPS on Tomcat in a Docker Container?
The first and the second ways are what I tried but it did not work. Even after the restart of my container.
The second is not the way I want to do it. My idea is to configure my server and have it on my repository as an image.
Here under, the configuration I added on my server.xml:
<!-- To generate a keystore certificate, here is the command:
keytool -genkey -alias fnsanzabandi -keyalg RSA -keystore fnsanzabandikeystore
-->
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="conf/fnsanzabandikeystore"
keystorePass="changeit" />
May be I missed something, or there is something else to do in the tomee case.
Can you please help me?
Thank you in advance.
Ok. My problem was silly.
After that configuration I kept running my tomcat container on port 8080 like this:
docker run --name tomee3 -p 8080:8080 fayabobo/tomee:1.2
That is why my my https port 8443 was not accessible. To resolve the problem, I just runned my tomcat container on port 8443 like this:
docker run --name tomee4 -p 8443:8443 fayabobo/tomee:1.2
And:

Docker Tomcat users configuration not working

Update: cleanup and directly indicate the problem and the solution.
PROBLEM:
Docker-tomcat was properly installed and running, except for the 403 Access error in the Manager App. It also seems that my docker tomcat cannot find my tomcat-users.xml configuration.
SOLUTION
Thanks to Farhad and Sanket for the answers.
[Files]:
Dockerfile
FROM tomcat:8.5.11
MAINTAINER Borgy Manotoy <borgymanotoy#ujeaze.com>
# Update Apt and then install Nano editor (RUN can be removed)
RUN apt-get update && apt-get install -y \
nano \
&& mkdir -p /usr/local/tomcat/conf
# Copy configurations (Tomcat users, Manager app)
COPY tomcat-users.xml /usr/local/tomcat/conf/
COPY context.xml /usr/local/tomcat/webapps/manager/META-INF/
Tomcat Users Configuration (conf/tomcat-users.xml)
<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="password" roles="manager-gui,manager-script" />
</tomcat-users>
Application Context (webapps/manager/META-INF/context.xml)
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true" >
<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
</Context>
[STEPS & COMMANDS]:
Build Docker Image
docker build -t borgymanotoy/my-tomcat-docker .
Run Image (my-tomcat-docker and set port to 8088)
docker run --name my-tomcat-docker-container -p 8088:8080 -it -d borgymanotoy/my-tomcat-docker
Go to the container's bash (to check files inside the container thru bash)
docker exec -it biyahe-tomcat-docker-container bash
First you need to expose your application in the container, so you can connect to it from dockerhost/network.
docker run -d -p 8000:8080 tomcat:8.5.11-jre8
You need to change 2 files in order to access the mangaer app from remote host. (Browser on Docker host is considered remote, only packets received on containers loopback are considered local for tomcat)
/usr/local/tomcat/webapps/manager/META-INF/context.xml Note the commented section.
<Context antiResourceLocking="false" privileged="true" >
<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
Please note the commented section.
/usr/local/tomcat/conf/tomcat-users.xml as you stated in the question.
<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="password" roles="manager-gui,manager-script" />
In order to make changes to files in the container, You can try building your own image, but I suggest using docker volumes or bind mounts.
Also make sure you restart the container so the changes take effect.
Please specify the port when you do a docker run like (i believe mine/tomcat-version is your image name),
docker run -p 8000:8080 -it -d --name MyContainerName mine/tomcat-version
then access the manager page using,
http://<ipaddress>:8000/manager/html
To get the host ip address in docker to need to execute docker-machine ip
Addition info: You can also get into the container using below command,
docker exec -it MyContainerName bash if you want to check different things like tomcat logs, conf files, etc.
Although this is quite late, I wanted to leave my 2 cents.
I took this solution to the next level by building a sample continuous integration system that deploys wars to the docker tomcat just by running mvn clean install via project IDE whilst having the docker tomcat container running.
This solves the problem of having to restart tomcat-container every time a new build is available. Takes advantage of tomcat's auto-deploy
Uses shared volume so that you can deploy multiple wars into the shared volume and a script picks up your wars and deploys to tomcat webapps
Comes with a standard user 'admin' so as to access manager GUI.
Available on public docker repo: docker run -p 8080:8080 -d --name tom -v <YOUR_VOLUME>:/usr/local/stagingwebapps wintersoldier/tomcat_ci:1.0
Picks up any war files dropped to the shared volume and instantly deploys them to tomcat server with an option to deploy it via GUI as well
Here is a sample application with required maven changes & docker file to explore

Resources