1

Im trying to set up a connection between my Docker container and my host that it is run on. Ive read Access host database from a docker container, and added the host ip to the hostfile of the Docker container, however it still will not respond to pings.

Im hosting my servers on an AWS box, and the ports 80, 8080 are open.

How can I get the host sever to respond to pings from the container?

Thanks.

Community
  • 1
  • 1
J. Doe
  • 1,479
  • 5
  • 25
  • 49

1 Answers1

3

You can run Docker container using "--net=host" option, then the container will share the same network namespaces with the host node.

For example:

sudo docker run -it --net=host ubuntu:14.04 bash

KiwenLau
  • 2,502
  • 1
  • 19
  • 23
  • Does that mean that the docker container has the same IP address as the host then? Doing `docker inspect` on the container shows the IP as being `"IPAddress": "",` after passing this parameter – J. Doe Apr 25 '16 at 12:53
  • Yes. And the container will share the same port numbers with the host. Therefore, the container can communicate with the host without problem. – KiwenLau Apr 25 '16 at 12:57
  • how do you do this using docker-compose? – Artanis Zeratul Jun 15 '19 at 13:32
  • 1
    @Artanis here is some useful link: https://forums.docker.com/t/option-network-mode-host-in-docker-compose-file-not-working-as-expected/51682/2 – Heril Muratovic Sep 03 '19 at 18:48