Is it possible to get host's info from within docker, for example
- HOST Machine's IP (eth0's IP not docker0's)
- Available RAM in HOST machine
etc.,
Thanks in advance
It's not generally possible - it would break the isolation which Docker provides.
In this article, you can see how, any breakout from the Docker container is actually a serious security issue.
https://blog.docker.com/2014/06/docker-container-breakout-proof-of-concept-exploit/
However, there are various workarounds:
http://blog.michaelhamrah.com/2014/06/accessing-the-docker-host-server-within-a-container/
Suggests that the following approach:
"Although there’s no way to introspect the host’s ip address (AFAIK) you can pass this in via an environment variable:"
docker@boot2docker:~$ docker run -i -t -e DOCKER_HOST=192.168.59.103 ubuntu /bin/bash root@07561b0607f4:/# env HOSTNAME=07561b0607f4 DOCKER_HOST=192.168.59.103 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PWD=/ On EC2, specifically, you can access the instance's metadata:
See
Fetching AWS instance metadata from within Docker container?
In particular:
$ curl http://169.254.169.254/latest/meta-data/hostname ec2-203-0-113-25.compute-1.amazonaws.com Other metadata options are listed here:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
docker run -it -p 9200:9200 -p 9300:9300 -e HOST_IP=$(hostname --ip-address) shan/elk:latest My use case is, I'm running elasticsearch inside docker and i need to pass the IP of the host machine to network.publish_host: parameter in elasticsearch Without passing the HOST_IP, auto discovery is not working Thank you very much Donald.curl http://169.254.169.254/latest/meta-data/local-ipv4.