Why when i start tomkat i get 404? - java

I just started to study docker.I want to run a site on tomcat in docker.i created Dockerfile.
FROM tomcat
ADD . ./webapps
EXPOSE 1234
CMD ["catalina.sh", "run"]
Ran it and everything loaded.
Step 1/5 : FROM tomcat
---> b0e0b0a92cf9
Step 2/5 : WORKDIR usr/local/tomcat/webapps
---> Running in ab6a23f95955
Removing intermediate container ab6a23f95955
---> 08731620b120
Step 3/5 : COPY . .
---> d6fe62efeaaa
Step 4/5 : EXPOSE 1234
---> Running in 18aadc814230
Removing intermediate container 18aadc814230
---> 445c749cb133
Step 5/5 : CMD ["catalina.sh", "run"]
---> Running in a3869dab8657
Removing intermediate container a3869dab8657
---> 6654588fc0f5
Successfully built 6654588fc0f5
Successfully tagged index:2.0
Existing container found: 2b36189ed9e57f8eaeae366485c1dc27acd4773ec18233e4e7b8c695e293e310,
removing...
Creating container...
Container Id: 3d1ee639b064a0ce0c1c38037ecc4b7f3cada03ffc6058b5fc903acb5e3cc519
Container name: 'my-container-2'
Attaching to container 'my-container-2'...
Starting container 'my-container-2'
'my-container-2 Dockerfile: Dockerfile' has been deployed successfully.
Now I want to open the site in a browser. I write url http://192.168.99.100:1234/index
but i get HTTP Status 404.Why?

It's very embarrassing to admit the decision))
The fact is that when I wrote all this, I did not start the container, so of course it did not work for me.You need to start the container in the console.

The way you describe the error sounds strange.
Your dockerfile shows us the script how a container is built. But you did not show how you ran docker build. Especially I do not see that you reconfigured Tomcat to listen on port 1234 - which means it will still be listening on port 8080. After docker build has run, you have a container image on the disk.
Next you do not show that you created and started a container as you would via docker run. Should I assume now there is no container running, or you have a container running that tries to listen to port 8080 and we do not know on which port it would be accessible (`docker run -p 1234:8080).
Not knowing what is listening on 192.168.99.100:1234 it is hard to say why you should get a HTTP error code 404.
Try to give more information about the commands you launched and their response, and tell us what you expect so we can help better.
Finally I know some people think my response should have been a comment. Try to put that much text into comments...

Related

Spring Boot in Docker container behind Nginx reverse proxy not working

I have a problem with a Spring Boot application running inside docker container, which is running behind nginx reverse proxy.
To check that docker and nginx are working correctly I've tried folloging, which worked as expected:
docker run -d -p 9001:80 nginx:alpine
My nginx config looks like
server {
server_name xyz.com;
listen 80;
location / {
proxy_pass http://localhost:9001;
}
}
Now I'm able to reach the nginx welcome page from the internet via xyz.com and let's assume the server's IP address is 123.123.1.1, via http://123.123.1.1:9001 as expected.
Also on the server itself, I get the welcome page via
curl http://localhost:9001
I think that shows, that docker and nginx are working as expected.
Let's go further down towards my problem.
Now I have build a simple Spring Boot application, which is bind to address 0.0.0.0 and port 9001. (Of course I have stopped the nginx container before going on...)
After the maven build, I have started the application with
java -jar app.jar
After it started up, I can reach it on the server with
curl http://localhost:9001
and from the internet via xyz.com and http://123.123.1.1:9001 - everything fine as expected.
Now, I've stopped the application und build a Dockerfile:
FROM amazoncorretto:11-alpine-jdk
COPY target/app.jar app.jar
ENTRYPOINT ["java", "-jar","/app.jar"]
First building the image with docker build -t app:latest . and afterwards run the container with docker run -p 9001:9001 -d app:latest. So far so good, the container starts up - fine.
And here is the problem:
I'm not able to reach the application neither via xyz.com nor on the server witch curl http://localhost:9001! But via http://123.123.1.1:9001 it worked!
I've tried to check it inside the container docker exec -it [container] sh and afterwards # wget localhost:9001 worked fine. # netstat -tulpn on the container itself brings following
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9001 0.0.0.0:* LISTEN 1/java
Also on the server $ netstat -tulpn shows the following:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9001 0.0.0.0:* LISTEN 607173/docker-proxy
tcp6 0 0 :::9001 :::* LISTEN 607180/docker-proxy
Maybe something with iptables, but not sure what.
Hopefully somebody out there has an idea to help me.
Thanks in advance!
Update
When I used port 80 inside the container (The Spring Boot application listen now on port 80 instead of 9001) - magically it works! Tried port 8080 inside the container also - this didn't work!
Looks like a port problem, maybe someone can explain where the problem is?!

How can I deploy cloudfoundry-uaa as a docker image based on tomcat?

We were using the cf-uaa's gradle tasks to create a docker image but those have been removed in the latest version. I've loaded the war in a recent version, but the service does not seem to be starting correctly.
I've been building the war from the v74 tag, adding it to tomcat:8.5.45-jdk12-openjdk-oracle or tomcat:9.0.24-jdk12-openjdk-oracle, and setting the various env vars that we were passing in to the previous image. I'm not seeing any log entries after the initial tomcat output stating that my war has been deployed and the server startup time.
The Dockerfile is basically just an adaptation of what was being passed in the previous image:
FROM tomcat:8.5.45-jdk12-openjdk-oracle
#FROM tomcat:9.0.24-jdk12-openjdk-oracle
ENV LOGIN_CONFIG_URL WEB-INF/classes/required_configuration.yml
ENV UAA_CONFIG_PATH /uaa
RUN bash -c "rm -r /usr/local/tomcat/webapps/ROOT"
RUN bash -c "rm -r /usr/local/tomcat/webapps/host-manager"
RUN bash -c "rm -r /usr/local/tomcat/webapps/manager"
RUN bash -c "rm -r /usr/local/tomcat/webapps/examples"
RUN bash -c "rm -r /usr/local/tomcat/webapps/docs"
ADD *.war /usr/local/tomcat/webapps/uaa.war
RUN bash -c "echo $LOGIN_CONFIG_URL"
EXPOSE 8080
I would expect to see the service responding to my requests, or some errors in the log indicating that the war failed to deploy. I am not currently getting any log output generated from the application code. When I send a request to the service, the response is a 500 with the an error header from the service.
X-Cf-Uaa-Error:Server failed to start. Possible configuration error.
update: I've located the uaa logs within .../tomcat/logs/uaa.log I'm not seeing anything indicating that the service failed to deploy, but I am also not seeing anything to indicate that it is picking up the env vars I have set in the container. I recreated the service using the war from the original setup which started successfully using the uaa.yml which I mounted as a volume. Comparing the logs, the original setup's first log entry is YamlProcessor which does not show up in the v75 logs at all. In fact, no debug entries show up at all, which suggests to me that my LOG_LEVEL env var is not propagating either.
Update 2: We reverted the image base to FROM tomcat:8.5-jre8 and started seeing flyway errors in the uaa.log. Our previous datasource url format was url: jdbc:postgresql://${POSTGRES_NAME}:5432/${DB}?currentSchema=uaa which caused a flyway exception. After removing the schema reference, it created the tables in the public schema. By creating the uaa schema manually before starting the service, it was able to run with the original format. The flyway version has updated, so perhaps there something new that needs to be set.
The application seems to be running, but when I try to get a token at /uaa/oauth/token I get a 500 with this error in the logs: Caused by: java.lang.NoSuchMethodError: java.nio.CharBuffer.limit(I)Ljava/nio/CharBuffer;
Since Jan 2021, UAA server docker images is now be available on cloudfoundry/uaa dockerhub repository.
docker pull cloudfoundry/uaa:75.0.0
See its Dockerfile for more details.
Can you try following ?
https://github.com/hortonworks/docker-cloudbreak-uaa
This works very well.

Debug tomEE on IntelliJ

I know that this answer was asked before, but I couldn't find a clear solution from the given answers.
I want to debug a maven project that implements a web service on tomEE using IntelliJ or any other IDE.
I know that instead of calling the goal tomee:run I must call tomee:debug. And that's what I did:
In IntelliJ, I click on Run / Edit Configurations then +, I chosen Maven, I located the project directory and I set tomee:debugas command line. I started the debug and it says:
Started server process on port: 8080
Listening for transport dt_socket at address: 5005
I think this first step is correct. The second step as I understood is to create a remote configuration, and this is what I failed to do.
What I did is the following:
Run / Edit Configurationsthen +, then TomEE Server. Here I choose local or remote? In my case I think local because the project is local on the device and I call it using localhost:8080.
After that, how to configure this page? What will be the port number 5005 or 8080? And when I finish configuring this page what I do? Run or debug?
I would appreciate a detailed answer because I was not able to understand the short answers given on other questions.
Here's the solution:
Step 1:
In IntelliJ, I click on Run / Edit Configurations then + to add a new configuration, I chosen Maven, I located the project directory and I set tomee:debugas command line. I started the debug and it says:
Started server process on port: 8080
Listening for transport dt_socket at address: 5005
An alternative solution can be by locating the project directory in terminal and running the command: mvn tomee:debug
Step 2: In IntelliJ, I click on Run / Edit Configurations then + to add a new configuration, I chosen Remote, and I specify localhost with port 5005.
Now I click OK, and I debug this configuration.
Breakpoints are detectable and debugging works perfect.

"Uncaught Could not connect" error when using Openshift to deploy .war for PHP/Java bridge

Problem: Recieve 'Could not connect' error when using Openshift to deploy .war for PHP/Java bridge
Below I describe every step I've taken to get to this error, thanks in advance.
Full error: (IP concealed)
"Fatal error: Uncaught Could not connect to the JEE server W.X.Y.Z:8080. Please start it. Or define('JAVA_HOSTS',9267); define('JAVA_SERVLET',false); before including 'Java.inc' and try again. Error message: Connection refused (111) thrown in /home/stevenw1/public_html/softwareProject/real/inc/Java.inc on line 989"
Players: "Java_Bridge.war" = my java .war file that php will use to call methods from
"W.X.Y.Z" = Unchanging IP address of deployed .war file
"GUIProfile" = a Java class with #WebServlet("/GUIProfile") as public class GUIProfile extends HttpServlet
"tomcattest.php" = test file that calls GUIProfile's static method 'validate'
Deployed Java_Bridge.war and tomcattest.php work fine on my local tomcat, just not yet on Openshift.
Senario:
0. followed command line steps from Openshift 2012 java tomcat application
1. Using Openshift's rhc I have created my first app using "rhc app create -a tomcat6 -t jbossews-1.0"
2. cd ~/tomcat6/; git rm -rf ./src/ pom.xml
3. cp ~/Java_Bridge.war ./webapps/; git add ./webapps/Java_Bridge.war; git commit -m "first try"; git push
//notable output includes:
remote: Stopping jbossews cartridge
remote: Sending SIGTERM to jboss:386662 ...
remote: Skipping Maven build due to absence of pom.xml
remote: Preparing build for deployment
remote: Deployment id is bd83d6eb
remote: Activating deployment
remote: + '[' Java_Bridge.war ']'
remote: Starting jbossews cartridge
remote: Found W.X.Y.Z:8080 listening port //(not actual IP)
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
to ssh://thisisnottheactualuser#tomcat6-notthenamehereeither.rhcloud.com
4. Thinking the .war was deployed I ran a tomcattest.php that calls a java method 'validate', from java class GUIProfile that extends httpservlet, using the php/java bridge Java.inc
//of course using the same IP from above...
cat tomcattest.php;
<?php
define("JAVA_HOSTS", "W.X.Y.Z:8080");
define("JAVA_SERVLET", "/Java_Bridge/GUIProfile");
require_once("Java.inc");
$valiationOutput = java_context()->getServlet()->validate("hello");
echo $valiationOutput;
?>
EDIT: later tried this also in all instances: same results exactly
cat alternatetest.php
<?php
define("JAVA_HOSTS", "W.X.Y.Z:8080");
require_once("Java.inc");
echo java("java.lang.System")->getProperties();
?>
The output of calling tomcattest.php is the 'Fatal error' you see at the top.
Double Check:
5. ssh thisisnottheactualuser#tomcat6-notthenamehereeither.rhcloud.com
6. env | grep "IP"
OPENSHIFT_JBOSSEWS_IP=W.X.Y.Z
7. env | grep "PORT"
OPENSHIFT_JBOSSEWS_HTTP_PORT=8080
OPENSHIFT_JBOSSEWS_JPDA_PORT=8787
8. changed port in tomcattest.php to 8787, didn't change a thing of course.
9. restarted from the top, this time keeping ./src/ & pom.xml, same 'Deployment completed with status: success', same error using tomcattest.php with new listening IP...
10. tried solution from 'openshift youtube vid 2012' seemingly outdated. Followed step by step:
onced ssh'ed, no "tomcat" dir, I used cd $OPENSHIFT_DATA_DIR instead to access data dir
wget tomcat, changed ports to >15000, sh startup.sh && tail -f ../logs/*
notable errors in the result include:
SEVERE: Failed to initialize connector [Connector[AJP/1.3-15009]]
org.apache.catalina.LifecycleException: Failed to initialize component
[Connector[AJP/1.3-15009]] SEVERE: Failed to initialize connector
[Connector[AJP/1.3-15009]] org.apache.catalina.LifecycleException:
Failed to initialize component [Connector[AJP/1.3-15009]] SEVERE:
Failed to initialize end point associated with ProtocolHandler
["ajp-bio-15009"] java.net.BindException: Permission denied
:15009 SEVERE: Failed to initialize end point associated with
ProtocolHandler ["ajp-bio-15009"] java.net.BindException: Permission
denied :15009
11. restarted step 6, this time left IP's as they were, changing only localhost to tomcat-stevenwernercs.rhcloud.com, same result but with original IP's
12. ran out of options online, then I posed this question...
13. then I edited it a lot...
14. patiently wait :)
That is everything I have done, I am not sure why php isnt finding Java.
I looked at previous questions didn't find anything helpful.
Open to anything, thank you
Gears in a non-scable application are not allowed to communicate on any non http/ws port. So if your php java bridge is trying to communicate with the tomcat instance on 15009 (from what i see above) that is not going to work. You could only make requests on 80/443/8000/8443. Can you verify what port the java bridge works over?
Alternate solution: https://bitnami.com/cloud
I got it working using Bitnami with Amazon AWS, it provides free service for 1 year, documentation that is easy to follow, and plentiful and up to date, It took less than an hour.
Disclaimer: Using ssh tunnel for port 8080 i configured tomcat as if on localhost, and moved my hosted .php to the
same microserver that also hosted the tomcat. (I gave up on trying to host php and tomcat separately.)
I have hosted tomcat separately before on my university's tomcat server. But that was a node I had full access to.
I would still like to try Openshifts free solution, although the current resources and methods I've seen seem to no longer be valid. And unfortunately the workarounds are not intuitive enough and are currently over my head. Thank you.

How do you run CruiseControl on MacOSX

What am I doing wrong?
Download Cruise Control
Unzip it -- Now it's in ~/Downloads/cruisecontrol-bin-2.8.4
Run ./cruisecontrol.sh
I see the server spinning up. The service binds to port 8080. So I wait a moment, then I go over to port 8080 using my browser.
This is what I see:
Error 404 - Not Found.
No context on this server matched or handled this request.
Contexts known to this server are:
/cc-config ---> org.mortbay.jetty.webapp.WebAppContext#519549e{/cc-config,file:/Users/darryl/Downloads/cruisecontrol-bin-2.8.4/webapps/cc-config/}
/cruisecontrol ---> org.mortbay.jetty.webapp.WebAppContext#420253af{/cruisecontrol,file:/Users/darryl/Downloads/cruisecontrol-bin-2.8.4/webapps/cruisecontrol/}
/dashboard ---> org.mortbay.jetty.webapp.WebAppContext#26c42804{/dashboard,file:/Users/darryl/Downloads/cruisecontrol-bin-2.8.4/webapps/dashboard/}
/documentation ---> org.mortbay.jetty.webapp.WebAppContext#181f327e{/documentation,file:/Users/darryl/Downloads/cruisecontrol-bin-2.8.4/webapps/documentation/}

Categories