How docker containers call each other

王林
Release: 2020-04-14 10:03:57
Original
4032 people have browsed it

How docker containers call each other

Method introduction:

Add the parameter link when running the container.

The specific steps are as follows:

1. Run the first container

docker run -it --name centos-1 docker.io/centos:latest
Copy after login

2. Run the second container

[root@CentOS ~]# docker run -it --name centos-2 --link centos-1:centos-1 docker.io/centos:latest
Copy after login

Parameter introduction:

--link: The first centos-1 in the parameter is the container name, and the second centos-1 is the defined container alias (use the alias to access the container). For ease of use, generally the alias defaults to the container name.

The test results are as follows:

[root@e0841aa13c5b /]# ping centos-1 PING centos-1 (172.17.0.7) 56(84) bytes of data. bytes from centos-1 (172.17.0.7): icmp_seq=1 ttl=64 time=0.210 ms bytes from centos-1 (172.17.0.7): icmp_seq=2 ttl=64 time=0.116 ms bytes from centos-1 (172.17.0.7): icmp_seq=3 ttl=64 time=0.112 ms bytes from centos-1 (172.17.0.7): icmp_seq=4 ttl=64 time=0.114 ms
Copy after login

Note: This method has requirements on the order in which containers are created. If multiple containers within the cluster need to access each other, it will be inconvenient to use.

Recommended tutorial:docker tutorial

The above is the detailed content of How docker containers call each other. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!