localhost docker

2025-01-13_localhost docker

2025-01-13T21:17:01+0800

Code Block:

Running matrix

Environment

  • Linux
  • Mac/Windows

Command

  • docker run
  • docker compose

docker run

Mac/Windows -> no idea yet

docker run --add-host host.docker.internal:host-gateway ...

Linux -> use host

docker run -it --network host ...

docker compose

Mac/Windows use host.docker.internal, cannot use localhost / 127.0.0.1

docker-compose.yaml

# ... services: serviceName: build: context: . dockerfile: ./Dockerfile ## For macos/Windows extra_hosts: - "host.docker.internal:host-gateway" # ...

Linux use host or bridge, and then can use localhost / 127.0.0.1 docker-compose.yaml

# ... services: serviceName: build: context: . dockerfile: ./Dockerfile ## For Linux network_mode: host # ...

References