Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vukhanhtruong/d01fffcd100a6cf4f59cf143b9b0281e to your computer and use it in GitHub Desktop.
Save vukhanhtruong/d01fffcd100a6cf4f59cf143b9b0281e to your computer and use it in GitHub Desktop.
How to connect from docker container to host

Two ways to reach host

  1. Use --network="host" in your docker run command, then 127.0.0.1 in your docker container will point to your docker host.

  2. Get host IP by running following command. Then you should reach the host from container.

ip addr show docker0 | grep -Po 'inet \K[\d.]+'

# 172.17.0.1

Alias for docker-compose

Add the following parameter to your service:

    extra_hosts:
      - "host.docker.internal:172.17.0.1"

Then you can reach via the alias path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment