Unable to connect Docker container to the service running locally: No route to host

Created:

2017-02-15 06:17:53 UTC

Modified:

2017-08-08 13:13:03 UTC

1

Was this article helpful?


Have more questions?

Submit a request

Unable to connect Docker container to the service running locally: No route to host

Applicable to:

  • Plesk for Linux

Symptoms

1. Docker container unable to connect to the services running on the same server (on the Docker host, not on another Docker container). Errors can be different based on the specific service, e.g. for MySQL service it can be:

MySQL Connection Error: (2002) No route to host

2. localhost variable or 127.0.0.1 used when specifying the path to the service.

Cause

localhost/127.0.0.1 are reserved by Docker container as a part of its own virtual environment.

Resolution

Use the server IP address instead of localhost variable or 127.0.0.1 .

E.g. let's assume it's needed to connect WordPress Docker container to MySQL database storing on the same server.

Specify the WORDPRESS_DB_HOST variable as 203.0.113.2:3306 , where 203.0.113.2 is the server's IP address and 3306 is the port used by MySQL DB server.

Check that the firewall is configured in the way to allow connection to the server from Docker container. Refer to this article to learn more about it - Unable to connect Docker container to external services, outside of the container: no route to host .

Have more questions? Submit a request
Please sign in to leave a comment.