Web server failed to start. Port 8080 was already in use - java

I am trying to develope a webapp using spring boot in STS. While running my app i am getting
Description:
Web server failed to start. Port 8080 was already in use.
Action:
Identify and stop the process that's listening on port 8080 or
configure this application to listen on another port.
I have tried to close the application for port 8080. I found the PID for the port and terminated it using
taskkill /F /PID pidname
I restarted the STS and tried to run again but its throwing the same error.

If port is acquired by some OS thread, it would be a bit tricky to stop it. Although it's not always great solution, but if you still want to continue with your development without any issue you can use this alternative solution (as you are in development environment).
Here is another thing you can use. You can replace the default port for Spring Boot server to some other port number.
For server port the property is server.port.
If you are using application.properties file:
server.port=8081
It will start server on port 8081.
Similarly, you can do the same if using an application.yml file:
server:
port : 8081
Each file is loaded by Spring Boot if placed in the src/main/resources directory of a Maven application.

Your only other option (beside making port 8080 available or using another port for spring boot) is running the application in docker:
Create a Dockerfile in your application directory
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Run in terminal
sudo docker build -t spring-app . && docker run -d -p 8080:8080 -t springapp
(This assumes you have docker installed, please install it if you don’t have it)

Related

How to access JMX interface in docker container on VM from outside?

I am trying to remotely monitor a JVM running in docker. The configuration looks like this:
machine: runs a JVM (in my case, Hello-World springboot app) in docker on an ubuntu machine (VM);
the IP of this machine is 10.10.1.29;
docker container has IP 172.28.0.3;
and to connect to VM by ssh I putted my creds
I have DockerFile of myApp
// some docker commands
EXPOSE 9010
CMD ["java", \
"-Dcom.sun.management.jmxremote", \
"-Dcom.sun.management.jmxremote.authenticate=false", \
"-Dcom.sun.management.jmxremote.ssl=false", \
"-Dcom.sun.management.jmxremote.port=9010", \
"-Dcom.sun.management.jmxremote.rmi.port=9010", \
"-Djava.rmi.server.hostname=10.10.1.29", \
"-jar /app/myApp-1.0.0.jar"]
the container starts and everything is super by docker-compose
config docker-compose.yaml:
// some yaml config
ports:
- "9010:9010" # JMX
I am running jconsole locally and tried to run this
service:jmx:rmi:///jndi/rmi://10.10.1.29:9010/jmxrmi
but connection failed
I tried different options but unfortunately unsuccessfully
Does anyone have a solution to this? Maybe the configuration is incorrect?
You will have to look into several issues here:
run the JVM with JMX enabled. Be aware of the port that is opened to access these values
run the docker container such that the port to the outside of the container
as the container is running inside some OS ensure there is no firewall preventing access to this port from outside the OS
as the OS is running inside a VM ensure that VM is fowarding traffic to the correct port
from outside the VM access the correct interface/port. If this access is from outside the host OS, ensure the host OS does not implement a firewall and forwards the traffic correctly
Failure on any of these points will simply not give you access.

Not able to access the docker containerised java web app on exposed port

I have Java web app in docker container.
Now container is exposed on host's port 8080 from container's port 8080 by running docker run command.
docker run -d -p 8080:8080 --name myTomcat -v $(pwd)/out/artifacts/DockerJavaWebAppWarExploded:/usr/local/tomcat/webapps/ tomcat:latest
There is no other process running on 8080 port ,but i am not able to access the application from browser http://localhost:8080/.
Container logs :
Please help.
It would be appreciated.
Check if http://0.0.0.0:8080 returns values. If yes, you may add an enrty for 0.0.0.0 in your hosts file.

How to write dockerfile for front end web app

Trying to deploy my first Java web app to Google Kubernetes. It must have 3 containers.
1 - front end web app
2 - back end Java web app- Jersey web service
3 - Postgres server
The whole web app is working on Eclipse Jee (Tomcat) on my laptop with no issue. The web app is very simple SPA with no Maven or Gradle build.
For backend: Dockerfile
FROM tomcat:9.0
ADD backend.war /usr/local/tomcat/webapps/backend.war
EXPOSE 8080
The image from the above is working fine. But for front end web app, I am really confused. Tried following variants without any success:
a)
FROM tomcat:9.0
ADD frontend.war /usr/local/tomcat/webapps/frontend.war
b)
FROM tomcat:9.0
COPY frontend.war /usr/local/tomcat/webapps/frontend.war
EXPOSE 8080
c)
FROM 8.0-jre8-alpine
COPY frontend.war /usr/local/tomcat/webapps/frontend.war
When I tried to access my site using the loadbalancer IP which google provided on browser, getting Not reachable message.
Here is my sample web application with backend as mysql database.
Front-end Dockerfile
FROM tomcat:9.0
ADD art-gallery-management.war /usr/local/tomcat/webapps/art-gallery-management.war
WORKDIR /usr/local/tomcat/
CMD ["catalina.sh" "run"]
EXPOSE 8080/tcp
Back-end Dockerfile
FROM mysql:latest
WORKDIR /docker-entrypoint-initdb.d
ADD Schema.sql /docker-entrypoint-initdb.d
CMD ["mysqld"]
EXPOSE 3306/tcp
Starting containers
docker container run -d --name art-gallery-management-db -e MYSQL_ROOT_PASSWORD=vision -p 3306:3306 bukkasamudram/art-gallery-management:db-latest
docker container run -d --name art-gallery-management-app --link art-gallery-management-db -p 8090:8080 bukkasamudram/art-gallery-management:app-latest
Make sure to use link option to link front-end container with back-end container.

Run a Docker Image as a Container (for windows users)

I built a docker image from a dockerfile. I see the image was built successfully (
$ docker images) and when I use this command to run the image as a container :
$ docker run -i -t 8dbd9e392a96
My application was running successfully, but when I'm trying to open I've this message
This site can’t be reached
This is my list of images :
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
blog latest b9c52b9f2999 About an hour ago 143MB
openjdk 8-jre-alpine 14a48fdee8af 3 days ago 83MB
and my containers list :
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4dbb68c87813 b9c52b9f2999 "./entrypoint.sh" 27 minutes ago Up 27 minutes 8080/tcp dazzling_shirley
I got this result after running the app using docker image :
----------------------------------------------------------
Application 'blog' is running! Access URLs:
Local: http://localhost:8080
External: http://172.17.0.2:8080
Profile(s): [dev, swagger]
----------------------------------------------------------
I dunno why the app didn't work any help please ?? !
Are you using docker toolbox for windows. Docker toolbox on windows runs docker in a Linux based virtualbox vm. You might have to open the port in the virtual box VM itself. So your host os can access the guest os's port.
See https://www.simplified.guide/virtualbox/port-forwarding
You have to map the docker container port to the host port. The reason is docker container is an isolated environment and it's public ip is same as that of the host machine. You have to ensure that host knows when to redirect requests to the container. So when you map the host port to docker container port, all the requests coming to HOST_IP_ADDRESS:HOST_PORT are redirected to the docker container whose port is mapped to the HOST_PORT.
You do that by using -p flag while using the docker run command as shown below:
docker run -it -p 8080:8080 IMAGE_NAME
Now all the requests coming to localhost:8080 will be directed to application running in container.

Changing port when running Jetty using jetty-runner

I'm executing the following command line:
java -jar C:\WorkArea\jetty-runner.jar c:\name.war --port 9090
I'm expecting it to run on port 9090 but it keeps on running using port 8080 which is the default.
What am I missing?
When running through eclipse itself, it is using 8888 so it's not taking this info from there, where/how else can I control the port?
Thanks
The documentation of the Jetty Runner suggests that the port option should be passed before the WAR file:
java -jar C:\WorkArea\jetty-runner.jar --port 9090 c:\name.war

Categories

Resources