0

I am trying to figureout from where to get the hostname of a running docker container that was started using docker-py.

Based on presence of DOCKER_HOST= file the started docker container my be on a remove machine and not on the localhost (machine running docker-py code).

I looked inside the container object and I was not able to find any information that would be of use for as 'HostIp': '0.0.0.0' is the remote docker host.

I need an IP or DNS name of the remote machine.

I know that I could start parsing DOCKER_HOST myself and "guess" that but this would not really be a reliable way of doing it, especially as there are multiple protocols involved: ssh:// and tcp:// at least.

I guess it should be an API based way of getting this information.

PS. We would assume that the docker host does not have firewall.

sorin
  • 161,544
  • 178
  • 535
  • 806
  • Possible duplicate of [How to get the IP address of the docker host from inside a docker container](https://stackoverflow.com/questions/22944631/how-to-get-the-ip-address-of-the-docker-host-from-inside-a-docker-container) – David Maze Feb 12 '19 at 00:13
  • Many of the answers to that question seem relevant. In general, since a container's network stack is isolated from the host's _by design_, this isn't something the container gets to know; it is essentially the same question as "my home router assigned my laptop an IP address of 192.168.1.2/24 but what's my _real_ external IP address"? – David Maze Feb 12 '19 at 00:14
  • @DavidMaze I am not saying that the container itself needs to know but docker server/connection should be able to report it. My question is about docker-py not reporting where the the port-binding occured... so if you started a container using docker-py you have no knowledge on how to connect to it using the the public interface.... not without doing some guessing. – sorin Feb 12 '19 at 11:12

2 Answers2

0

For the moment I ended up creating a bug on https://github.com/docker/docker-py/issues/2254 as I failed to find that information with the library.

sorin
  • 161,544
  • 178
  • 535
  • 806
-1

The best method is probably to use a website like wtfismyip.com. You can use

curl wtfismyip.com

to print it in terminal, and can then extract the public ip from the output.

Tom Atix
  • 381
  • 1
  • 21