Anthony O.
Anthony O.

Reputation: 24457

How to get the ip address of the docker host (which will be used in containers) from the host itself

I want to run a container and pass it the host IP (which will be visible by the container) as an environment variable to my container, how can I do that ?

Here is what it should like:

docker run -it --rm -e HOST_IP=`script which will give me the host IP visible by the future running container` myimage

Upvotes: 1

Views: 80

Answers (1)

Anthony O.
Anthony O.

Reputation: 24457

docker run -it --rm -e HOST_IP=`/sbin/ip route | awk '/docker/ {print $9 }'` myimage

Upvotes: 1

Related Questions