1

I have a docker-compose file and running containers

Inside one of the container i have to access the host ip

I get into the container

docker-compose exec webapp /bin/bash

and then checking the below command inside the container

ping host.docker.internal

it says

ping: host.docker.internal: Name or service not known

How to access host ip inside the container

I have to use host ip because i have to access the ssh tunnel on host

Santhosh
  • 9,965
  • 20
  • 103
  • 243
  • looks fine to me. `ping host.docker.internal` should usually return an astonishing timing < 2ms. No ports need to be exposed, you have always access to the host. How does the Dockerfile look like? – max Mar 29 '23 at 07:14

1 Answers1

-1

I found the answer

in the docker-compose file had to add:

  webapp:
    image: "python3.10.10_custom_build:latest"
    extra_hosts:
      - "host.docker.internal:host-gateway"

and inside the container we can access

ping host-gateway

https://stackoverflow.com/a/24326540/2897115

enter image description here

Santhosh
  • 9,965
  • 20
  • 103
  • 243