Shan
Shan

Reputation: 2221

Is it possible to get host details from within docker container?

Is it possible to get host's info from within docker, for example

  1. HOST Machine's IP (eth0's IP not docker0's)
  2. Available RAM in HOST machine

etc.,

Thanks in advance

Upvotes: 3

Views: 4670

Answers (1)

Donald_W
Donald_W

Reputation: 1823

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

Upvotes: 4

Related Questions