localhost docker on macOS

2025-01-13

Running tech stacks

[strong]

  • Linux

  • Mac/Windows

[strong]

  • docker run

  • docker compose

Mac/Windows -> host.docker.internal

[code]docker run --add-host host.docker.internal:host-gateway ...

Linux -> use host

[code]docker run -it --network host ...

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

docker-compose.yaml

[code]# ... 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 [inlineCode]localhost / [inlineCode]127.0.0.1 docker-compose.yaml

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

References

  • [link]