Niels B.
Niels B.

Reputation: 6310

Getting IPv4 address of Docker host

I have an application running in a Docker container. This application exposes some resources in it's API. These resources must be exposed with their full urls, this includes scheme, host, port and path.

From inside the container, it looks like my IP address (host) is 172.17.0.2. This is probably because the container is part of the internal Docker network.

However, the host has an eth0 device with an IP of 192.168.1.* and this is the one I want to know and include in the url's.

I understand that I can evaluate it when I create the container and pass it as an environment variable, but it would be nice with a solution that does not involve recreating the container if the Docker host IP address changes.

I know that I could set up a service on the host to periodically write the IP address into a volume and then read it from there, however I would like to have as few moving parts as possible outside of the container.

Upvotes: 1

Views: 258

Answers (1)

Alejandro Galera
Alejandro Galera

Reputation: 3691

Launch the docker container with --net=host and all interfaces of your host will be accessible from container, even of course your 192.168.1.X.

Upvotes: 2

Related Questions