Connecting with JMX using Docker for Mac - macos

I'm struggling with setting up a JMX connection to Tomcat running in a Docker container using Docker for Mac.
I think I understand the basics, and have a setenv.sh in the tomcat/bin directory looking like this:
CATALINA_OPTS="-Dcom.sun.management.jmxremote=true\
-Dcom.sun.management.jmxremote.local.only=false\
-Dcom.sun.management.jmxremote.authenticate=false\
-Dcom.sun.management.jmxremote.ssl=false\
-Djava.rmi.server.hostname=185.83.15.228\
-Dcom.sun.management.jmxremote.port=9999\
-Dcom.sun.management.jmxremote.rmi.port=9999"
I think the problematic part might be the java.rmi.server.hostname property. I've set this to the IP of the host machine, but I've also tried other obvious things. I believe this should be the IP of the machine on which jconsole or jvisualvm will be running, but this is not working for me.
I start the container like this:
docker run -d -v /Users/timbo/tomcat-jmx.sh:/usr/local/tomcat/bin/setenv.sh -p 8080:8080 -p 9999:9999 tomcat:8.0
so port 9999 is exposed.
When I try to connect using jvisualvm connecting to localhost:9999 (which Docker for Mac will route to the container which is actually on 172.17.0.2) I get the error:
Cannot connect to localhost:9999 using service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi
Any hints on what is wrong?

OK, I think I managed to find it eventually. Setting the value of java.rmi.server.hostname to the hostname of the host (e.g. mymac.local, or whatever is returned by hostname) seem to get it working. All other settings were OK.

Docker for Mac works in a bit different way. The port you map actually gets mapped to the Linux VM it is running in the background. This VM usually has in IP 192.168.99.100. So you should try and connect to 192.168.99.100:9999
To verify what is the IP of your VM, open the Docker CLI terminal and execute below
echo $DOCKER_HOST
tcp://192.168.99.100:2376

Related

Cannot forward ports when running Linux container on Windows10 as a host

I'm new using Docker. I have been trying to deploy a Linux container (with Windows as a host) with a Google Cloud image inside using Docker. I'm able to do everything well, at the end the server is running perfectly, but when I want to check the server, using the localhost in the browser, I got a blank page with:
Blank page
This is the Dockerfile:
FROM google/cloud-sdk
ENV PATH /usr/lib/google-cloud-sdk/bin:$PATH
WORKDIR docker_folder
COPY local_folder/ .
RUN pwd
EXPOSE 8080
CMD ["java_dev_appserver.sh", "."]
This is the command I'm using to build my image (in the CMD):
docker build --tag serverdeploy .
This is the command I'm using to run my container
docker run -p 8080:8080 serverdeploy
This is the stack trace that I got when I run the server
where I know that I running the server
I did some research and looks like Docker had a problem with the ports when you use a Linux container in Windows (Not sure if it's already solved or not). I've already tried all the possible solutions that I found out there (even trying to replace 'localhost' by all the ip's that I get when I run ipconfig on the cmd) but I still get the same error.
And, as last hope, I need your help to understand what I'm doing wrong, or if I missing something
You are running your service bind to localhost - that means no remote connections are accepted (as well as binding to 127.0.0.1. And for your container the host is a remote connection.
Change binding to 0.0.0.0 (which I guess is default) and enjoy.
Btw sharing your java_dev_appserver.sh would be helpful for answering the question.

Not able to bind to docker container port

I manage to have Windows Server 2016 and Windows Container installed in my VirtualBox for testing.
I also follow the guide here https://github.com/Microsoft/Virtualization-Documentation/tree/master/windows-server-container-samples/iis-10.0 to build an image with iis installed.
However I'm not able to bind port 80 from container to any port in the host, here's how I run the container with port mapping and result of docker ps command:
I also try -p switch without explicitly telling the port mapping, but that doesn't work either
I tried to attach to the container and request the default iis web page using wget and everything seems fine:
And here's result of the docker inspect the container, in the exposedports section, it says port 80/tcp is exported, but not sure why it's not reflected in the host machine. Can someone give me an idea where I go wrong? Or is this a bug from Windows Container? I tried to post in msdn forum but their process of verifying account is really troublesome
https://api.myjson.com/bins/4a1f4

Why did the IP and port number change in Kitematic?

I am running Mac OS 10.10.3.
I am using Kitematic and Docker in a development environment. Yesterday I installed a container for Postgre. The mac ip and port for this container was 192.168.99.100:5432.
I shut down my system for the day.
Today, when I restarted my system, started Kitematic, and started the containner The ip and port was 192.168.99.100:32771.
Why did it change?
This is now supported. Click on Settings, then ports, click on the port and you can change it.
Issue on kitematic github.
I assume that you are not designating the port when you start your container and instead it is run with the -P option, which assigns a random port to any exposed ports. If you use the -p HOSTPORT:GUESTPORT option instead of -P the port will be consistent.
Check out the Expose and Run documentation
I think this feature has not been implemented yet.
https://github.com/kitematic/kitematic/issues/164
I don't believe kitematic supports assigning ports and only does the equivalent of the -P option of docker run.

dockerizing an application on Mac OS X

I installed boot2docker as explained on the docker website. Here are some command runs to show that I have things installed correctly:
$$:~ kv$ boot2docker start
Waiting for VM and Docker daemon to start...
...................ooo
Started.
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/key.pem
Your environment variables are already set correctly.
$$:~ kv$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 b39b81afc8ca 11 days ago 188.3 MB
hello-world latest e45a5af57b00 3 weeks ago 910 B
After this, I ran the following command:
docker run -t -i ubuntu:14.04 /bin/bash
Inside the container, I installed zeromq, and started a zeromq server on port 5555 using tcp.
My questions are following:
If I exit out of the container, will it save all the work I do inside it?
I have no idea how to connect to the server running on port 5555. I read something about exposing a port, but I am not sure how to go about doing that. I did an ifconfig inside the container, and tried to connect to the server from the host like this:
$$:~ kv$ ./zmq_client tcp://container_ip:5555
This did not work. Can someone please lists the steps I need to take in order to connect to the server running within the container.
For completion sake, I am providing the list of my environment variables:
TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/km/5kbpdx4s7cg4rmyc6d5q9l9r0000gq/T/
DOCKER_HOST=tcp://192.168.109.103:2376
Apple_PubSub_Socket_Render=/tmp/launch-1tWMHJ/Render
TERM_PROGRAM_VERSION=326
OLDPWD=/Users
TERM_SESSION_ID=262CBC8B-0A74-4B70-9F28-D9FA51FF713C
USER=kv
SSH_AUTH_SOCK=/tmp/launch-ZTWNGL/Listeners
__CF_USER_TEXT_ENCODING=0x1F7:0:0
DOCKER_TLS_VERIFY=1
__CHECKFIX1436934=1
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
PWD=/Users/kv
DOCKER_CERT_PATH=/Users/kv/.boot2docker/certs/boot2docker-vm
HOME=/Users/kv
SHLVL=1
LOGNAME=kv
LC_CTYPE=UTF-8
DISPLAY=/tmp/launch-rco9zt/org.macosforge.xquartz:0
_=/usr/bin/env
One last question I have is about code performance. So within my Mac OS X, I have a docker container running (which runs Ubuntu). If I run the application, like a zeromq based server inside the container, will it not be slower as compared to running it on Mac OS X directly. Please explain the benefits of using docker in such a scenario..
You should really do some more reading and research before turning to SO, then ask about anything you can't figure out. But:
No. If the container is "exited" you can restart it and your files will still be there, but once it is removed your files are gone. You can use docker commit to save them to an image, but the best bet is to use a Dockerfile.
docker run -p 5000:8000 image will expose port 8000 in the container as port 5000 on the host.
Yes, it will be slower due to the boot2docker VM. It would not be slower if you were running on a Linux host. The advantage is that zeromq is now running in an isolated container with all its dependencies.

Port forwarding issues trying to run a docker container

I am new to docker and nowhere near a networking expert, but I am seeing some strangeness when trying to run a docker container instance (right word?). I am running docker on OSX and set it up using the documentation found here: http://viget.com/extend/how-to-use-docker-on-os-x-the-missing-guide
Everything seems to have gone along fine, then I set up the port forwarding rules via these lines:
for i in {49000..49900};
do VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i";
done
I can confirm the boot2docker VM instance by checking the configuration within the Oracle VM VirtualBox Manager->Network->Adapter 1->Port Forwarding with the OSX.
I then run this command to get the container.
docker run -d -P dockerhub.emory.edu/ecoi_trunk:2
I do a "docker ps" and get this info.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f20bfefa2e97 dockerhub.emory.edu/ecoi_trunk:2 "/usr/sbin/apachectl 18 seconds ago Up 15 seconds 0.0.0.0:49153->443/tcp, 0.0.0.0:49154->80/tcp cranky_einstein
However, when I run an "lsof -i :49153" I see nothing is listening. I also can't reach the container via the "l****host:49153" in my browser. It just hangs.
What's strange is if I explicitly set the port (rather than allowing docker to assign one) via the following command:
docker run -d -p 49000:80 dockerhub.emory.edu/ecoi_trunk:2
It seems to work (lsof -i:49000 displays a TCP LISTEN), and I can confirm it's listening and the container is reachable via "l****host:49000". However, it's extremely slow. I'm not sure if either are related, but would welcome any tips or thoughts.

Resources