Container network interconnection

Last Updated: May 14, 2018

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.

  1. network-test1:
  2. image: busybox
  3. hostname: server1
  4. command: sh -c 'ifconfig eth0; sleep 100000'
  5. tty: true
  6. environment:
  7. - 'constraint:aliyun.node_index==1'
  8. network-test2:
  9. image: busybox
  10. hostname: server2
  11. command: sh -c 'ifconfig eth0; sleep 100000'
  12. tty: true
  13. environment:
  14. - 'constraint:aliyun.node_index==2'

Test methods

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

1

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.

1

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.

1

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.

1

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.

1

Thank you! We've received your feedback.