No route to host error when two Docker containers are interconnected

Source: Internet
Author: User
Tags docker run

As we all know, two Docker container can be connected with link, but we also know that container can map its own port to a host, such as a Tomcat on container A to expose the port to the host (0.0.0.0 : 58080->8080), the other MySQL on container B also exposes the port to the host (0.0.0.0:53306->3306), so the question is whether you can change the JDBC connection on a to jdbc:mysql:// 192.168.1.10:53306xxxxxx (assuming that 192.168.1.10 is the IP of the host), suddenly it seems to be possible, no firewall, the port has been mapped, it should be able to connect, but in fact, on Tomcat, I encountered no route to Host error, the specific experiment is as follows:

First we start a MySQL container, exposing the 3306 port to the host:

1[[email protected] ~]# Docker run-d-P53306:3306-E mysql_root_password=123456test01/mariadb2 2c564a3484a4424b18e413fb11c6a71d76098f7e2e30b3ea8ad4e1b987e249a83[email protected] ~]# DockerPS 4 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES52C564A3484A4 test01/mariadb"docker-entrypoint.sh"    $Seconds ago Up +Seconds0.0.0.0:53306-3306/TCP Berserk_cray6[Email protected] ~]#

This time we use the client to visit, test 53306 This port can be connected to our database:

The connection succeeded, indicating that the port mapping was successful, and that the 53306 port that accessed the host from the outside could properly map to port 3306 on the container.

Ok, next, start a Tomcat container and point the application's JDBC connection to Port 53306 of the host to see if it can be connected.

1[email protected] ~]# Docker run-it-p52080:8080test01/wbserv/bin/Bash2[Email protected]/]#SH/opt/apache-tomcat-7.0. -/bin/startup.SH 3Using catalina_base:/opt/apache-tomcat-7.0. -4Using Catalina_home:/opt/apache-tomcat-7.0. -5Using Catalina_tmpdir:/opt/apache-tomcat-7.0. -/Temp6Using jre_home:/usr/java/jdk1.7.0_79/JRE7Using CLASSPATH:/opt/apache-tomcat-7.0. -/bin/bootstrap.jar:/opt/apache-tomcat-7.0. -/bin/tomcat-Juli.jar8 Tomcat started.9[Email protected]/]#

At this point, Tomcat is up, and the next step is to configure the app and open the app: (note IP and port numbers, both with the host's IP and Ports)

OK, next, launch the app, you can see that the app doesn't come up, and then look under the startup log:

Tail  Logs/catalina.out

Hint at the beginning of this error, No route to host.

This problem, estimates can be resolved by modifying the Hosts file, but I do not have this to do, there are friends who want to go to try, finally considering that there will be a large-scale deployment of the need, this is changed to link connection, such as:

--link Mysql_name:tomysql

You only need to change the original JDBC connection to

Jdbc:mysql://tomysql:3306/drools?characterencoding=utf-8

Restart the application and solve the problem.

No route to host error when two Docker containers are interconnected

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.