This document provides a simple Compose file used to realize one-click deployment and you can test the container network connectivity by visiting the service access endpoint.
When deploying interdependent applications in a Docker cluster, you must make sure that the applications can access each other to realize cross-host container network connectivity. However, sometimes containers on different hosts cannot access each other due to network problems. If this happens, it is difficult to troubleshoot the problem. Therefore, an easy-to-use Compose file can be used to test the connectivity among cross-host containers within a cluster.
Use the provided image and orchestration template to test the connectivity among containers.
web: image: registry.aliyuncs.com/xianlu/test-link command: python test-link.py restart: always ports: - 5000 links: - redis labels: aliyun.scale: '3' aliyun.routing.port_5000: test-link; redis: image: redis restart: always
This example uses Flask to test the container connectivity.
The preceding orchestration template deploys a Web service and a Redis service. The Web service contains three Flask containers and these three containers will be evenly distributed to three nodes when started. The three containers are on different hosts and the current network can realize cross-host container connectivity if the containers can ping each other. The Redis service runs on one of the three nodes. When started, each Flask container registers to the Redis service and reports the container IP address. The Redis service has the IP addresses of all the containers in the cluster after the three Flask containers are all started. When you access any of the three Flask containers, the container will send ping command to the other two containers and you can check the network connectivity of the cluster according to the ping command response.
- Create a cluster which contains three nodes.
In this example, the cluster name is test-link. For how to create a cluster, see Create a cluster.Note Select to create a Server Load Balancer instance when creating the cluster.
- Use the preceding template to create an application (in this example, the application
name is test-cluster-link) to deploy the web service and redis service.
For how to create an application, seeCreate an application.
- On the Application List page, click the application name to view the created services.
- Click the name of the web service to enter the service details page.
You can see that the three containers (test-cluster-link_web_1, test-cluster-link_web_2, and test-cluster-link_web_3) are all started and distributed on different nodes.
- Visit the access endpoint of the web service.
As shown in the following figure, the container test-cluster-link_web_1 can access the container test-cluster-link_web_2 and container test-cluster-link_web_3.Refresh the page. As shown in the following figure, the container test-cluster-link_web_2 can access the container test-cluster-link_web_1 and container test-cluster-link_web_3.
As the preceding results show, the containers in the cluster can access each other.