Skip to content

Instantly share code, notes, and snippets.

@juev
Created March 20, 2025 09:16
Show Gist options
  • Save juev/e0dd743895602c3a7305b9e75d018735 to your computer and use it in GitHub Desktop.
Save juev/e0dd743895602c3a7305b9e75d018735 to your computer and use it in GitHub Desktop.

From inside of a Docker container, how do I connect to the localhost of the machine?

Источник

If you are using Docker-for-mac or Docker-for-Windows 18.03+, connect to your mysql service using the host host.docker.internal (instead of the 127.0.0.1 in your connection string).

If you are using Docker-for-Linux 20.10.0+, you can also use the host host.docker.internal if you started your Docker container with the --add-host host.docker.internal:host-gateway option, or added the following snippet in your docker-compose.yml file:

extra_hosts:
    - "host.docker.internal:host-gateway"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment