Access host machine service from within docker container
To access the host machine's service running on a local port from within a docker container, use the special URL host.docker.internal to access the host services.
This soluction works on the following installation types of Docker:
- Docker Engine on Linux
- Docker Desktop on Linux, Mac and Windows
- Colima on Mac
Example using docker
docker run --add-host=host.docker.internal:host-gateway --rm alpine/curl -fsSL http://host.docker.internal:8080/health-check
Example using docker compose
networks:
main:
name: my-docker-compose-network
services:
curl:
container_name: curl
image: "alpine/curl"
extra_hosts:
- host.docker.internal:host-gateway
command: curl -fsSL http://host.docker.internal:8080/health-check
networks:
main:
aliases:
- curl
Comments
Post a Comment