Is there a way to find out from inside a Docker container whether that container is running natively on a Linux host, or in Docker Machine?
The background of the question is that I want to enable JMX in my Tomcat-based container, but for that, I need to know the external IP address of the host:
- When running in Docker-Machine, this is something like 192.168.99.100.
- Running natively on Linux, this is the IP address of the host.
- Running in Docker for Mac, this is also the IP address of the host.
I have a Docker Tomcat image that I want to roll out with JMX enabled, but I don't know whether people are going to use it natively or running in Docker-Machine, hence I don't know which IP address to provide for the java.rmi.server.hostname
parameter when starting Tomcat.
Is there a way to either
- find that IP address from inside of the container (or find out where it's running), or
- find it out from the outside (e.g. in docker-compose) and then pass it into the container upon start? Can the
DOCKER_HOST
environment variable help in this case? When running Docker Machine, it's set totcp://192.168.99.100:2376
- is this variable also used when not running Docker Machine?
I would like to avoid the situation where people have to provide the IP address manually when starting the container (or Docker Compose).