Container network interconnection

Container Service creates the global network for containers, and the containers in the cluster can access other containers by using the eth0 network interface of the container.

Orchestration example

For example, create containers on two machines respectively and record the IP addresses, names, and hostnames of the containers. Log on to the container web terminal and test the network communication across nodes for these two containers by using the ping command.

network-test1:

image: busybox

hostname: server1

command: sh -c 'ifconfig eth0; sleep 100000'

tty:true

environment:

-'constraint:aliyun.node_index==1'

network-test2:

image: busybox

hostname: server2

command: sh -c 'ifconfig eth0; sleep 100000'

tty:true

environment:

-'constraint:aliyun.node_index==2'

Test methods

The containers of these two services are distributed in different nodes.

Test network communication by using container IP address

By using the Container Service console or the ifconfig eth0 log output by container test_network-test1_1, you can see the IP address of container test_network-test1_1 is 172.20.15.4. Then, you can connect to the web terminal to access the IP address of container test_network-test1_1 in container test_network-test2_1 to test whether or not the network communication works.

Enter sh in the shell field and then click Execute. Then, enter the command ping 172.20.15.4.

Test network communication by using container name

You can view the container name on the details page of the corresponding container. The default container name is {project-name}_{service-name}_{container-index}. In this example, the container name is as follows.

Enter sh in the shell field and then click Execute. Then, enter the command ping test_network-test1_1 to test the network communication by using the container name.

Test network communication by using hostname

In this example, the hostname is specified in the orchestration template. Therefore, you can also test the network communication by using the hostname.