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
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 have one war file with the following MySQL setup; I wanted to compile it using Dockerfile so that I could utilise the mysql docker image.
However, I am missing/not properly configuring something, and as a result, I am receiving connection errors.
url: jdbc:mysql://localhost:3307/test-db
username: root
password: yum-hai-hum
DockerFile
FROM mysql:5.7
ADD test-db.sql /docker-entrypoint-initdb.d
EXPOSE 3307
ENV MYSQL_ROOT_PASSWORD=yum-hai-hum
ENV MYSQL_DATABASE=test-db
ENV MYSQL_USER=root
ENV MYSQL_PASSWORD=yum-hai-hum
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=build/libs/*.war
COPY ${JAR_FILE} app.war
ENTRYPOINT ["java","-jar","/app.war"]
Error:
Build and run command for image and container:
docker build -t="navin/java-app" .
docker run -e "SPRING_PROFILES_ACTIVE=dev" -p 8080:8084 -t navin/java-app
url: jdbc:mysql://localhost:3307/test-db
correct me if i`m wrong,
The host of Mysql server is container1-ip:3307
the war app is on container2, and it is trying to connect to localhost:3307
probably change host of url from localhost to something like 192.168.100.19. You can get the actual ip using command ifconfig on the first container
The default Docker container access host IP is 172.17.0.1 , If you have a MySQL port 3306 that maps to the host, you can use the
url: jdbc:mysql://172.17.0.1:3306/test-db
I just want to deploy my springboot applicaiton on the remote centos server through the intellij idea.
First I tried the way of DockerFile to deploy the application on intellij idea and I successed.
this is my DockerFile config
FROM williamyeh/java8
# COPY or ADD to image
COPY dockerdemo-0.0.1-SNAPSHOT.jar app.jar
RUN bash -c "touch /app.jar"
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
but when I tried the method of docker-compose.yml,I failed,I can't mapped my navtive jar to the remote system.my docker-compose.yml config is
version: "3"
services:
dockerDemo2:
image: adoptopenjdk/openjdk8:latest
container_name: dockerDemo2
privileged: true
environment:
TZ: Asia/Shanghai
LANG: es_US.UTF-8
volumes:
- ./dockerdemo-0.0.1-SNAPSHOT.jar:/docker/dockerdemo-0.0.1-SNAPSHOT.jar
command: bash -c " tail -f /dev/null "
ports:
- 8080:8080
I deployed successed,but when I get in the remote docker ,I found the /docker/dockerdemo-0.0.1-SNAPSHOT.jar is a directory, It should expected as a jar file,but it not,I don't know why that.that's really confuesed me.
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 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.