Unable to connect Docker container to external services, outside of the container: no route to host

Created:

2017-02-15 06:17:26 UTC

Modified:

2017-08-08 13:10:13 UTC

2

Was this article helpful?


Have more questions?

Submit a request

Unable to connect Docker container to external services, outside of the container: no route to host

Applicable to:

  • Plesk for Linux

Symptoms

1. Docker container can not connect to the external services running outside of the container, on the remote server or Docker host. 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. Services itself are up and running.

Cause

Firewall rejects inbound connections from Docker container.

Resolution

Configure firewall on the remote server or Docker host to allow connections on the host's specific port from the docker0 interface.

E.g let's assume that error occurs when Docker container was connecting to MySQL database. First find out the IP address of Docker host:

# ip addr show docker0

Next let's configure firewall to allow connections on the port 3306 from the docker0 interface. Replace 203.0.113.2 with the IP address discovered on the previous step.

# iptables -A INPUT -p tcp -s 203.0.113.2 --dport 3306 -i docker0 -j ACCEPT

The command above should be executed on remote server or local server where Docker is running.

If the service is running on the same server with Docker application and firewall is configured, but the issue still persists, then check this article - Unable to connect Docker container to the service running locally: No route to host .

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