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.
Related
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.
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)
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.
I'm trying to test a microservice running from docker.
Without docker I can access it on http://localhost:9999/
When I build the image, run it and try the same address http://localhost:9999/ I get err_connection_refused
In my dockerfile I
EXPOSE 9999
And when running the image I map ports
docker run -i -t 6bcb62617b00 -p 9999:9999
But this dosn't help.
`Docker-machine` ls returns `tcp://192.168.99.100:2376`
I am using docker quickstart terminal for testing.
This is the message I get when running the image Tomcat started on port(s): 9999
docker ps
Seems like it had something to do with the way I run it.
Here
docker run -d --network=name -p 9999:9999 beeline/dim_source_taxon
Instead of image id I use repository to start microservice and when I try
docker ps
I get
Also, instead of localhost I have to use the host provided by comand docker-machine ls
I'm running Docker on OS X using the latest Docker Toolbox.
Docker version 1.10.2, build c3959b1
docker-machine version 0.6.0, build e27fb87
docker-compose version 1.6.0, build d99cad6
I have a Java app in a container built from the following Dockerfile:
FROM <my internal registry>/java:8
ENTRYPOINT ["java", "-cp", "/var/app/scheduler/scheduler-jar-with-dependencies.jar", "com.myapp.scheduler.Application"]
and docker-compose.yml:
scheduler:
image: <my internal registry>/scheduler
command: -Dspring.profiles.active=local -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5050
environment:
TERM: xterm
ports:
- "4567:4567" # http port
- "5050:5050" # java debug port
volumes:
- $SCHEDULER_GIT_ROOT/target:/var/app/scheduler
- $LOG/scheduler:/var/log/scheduler
When I bring up the container, I can hit the http port from the browser using the VMs IP (192.168.99.100:4567). I can't connect my debugger to the debug port, however, nor can I access that port at all through telnet, no matter what I change the port to. docker ps yields:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9395e0f20dd5 <my registry>/scheduler "java -cp /var/app/sc" 7 minutes ago Up 7 minutes 0.0.0.0:4567->4567/tcp, 0.0.0.0:5050->5050/tcp scheduler_scheduler_1
Anyone know why I can connect to the one port, but not the other?
EDIT: Here's the command from docker inspect:
"Path": "java",
"Args": [
"-cp",
"/var/app/scheduler/scheduler-jar-with-dependencies.jar",
"com.mlbam.cms.scheduler.Application",
"-Dspring.profiles.active=local",
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5050"
]
This wound up having nothing to do with Docker, but rather with the way I was running the java command. The debug args have to come before the -cp:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5050 -cp /var/app/scheduler/scheduler-jar-with-dependencies.jar com.myapp.scheduler.Application