Skip to main content

Docker - Access Local Services

Learn how to access host servcies from a docker container.

Sometimes, having a Dockerized project, we might need to access local sevices like Redis, MySql or PostgreSQL. This use case is supported by Docker when we set in the environment the hostname to host.docker.internal instead of using the traditional localhost or 127.0.0.1 witch might lead to runtime errors like this:

connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address


Some well-known local services we can access from a Docker Container

  • Redis: port 6379, hostname host.docker.internal, instead of localhost
  • MySql: port 3306, hostname host.docker.internal, instead of localhost
  • Postgresql: port 5432, hostname host.docker.internal, instead of localhost

Docker, Access Local Services - Tutorial provided by AppSeed


✅ Resources​