docker容器之间怎么互相调用

docker容器之间怎么互相调用,第1张

docker容器之间怎么互相调用

方法介绍:

运行容器的时候加上参数link。

具体步骤如下:

1、运行第一个容器

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

2、运行第二个容器

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

参数介绍:

--link:参数中第一个centos-1是容器名,第二个centos-1是定义的容器别名(使用别名访问容器),为了方便使用,一般别名默认容器名。

测试结果如下:

[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

注意:此方法对容器创建的顺序有要求,如果集群内部多个容器要互访,使用就不太方便。

推荐教程:docker教程

以上就是docker容器之间怎么互相调用的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/709731.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-24
下一篇 2022-04-24

发表评论

登录后才能评论

评论列表(0条)

保存