(1)安装两个tomcat容器
[root@localhost ~]# docker run -d -P --name tomcat01 tomcat
[root@localhost ~]# docker run -d -P --name tomcat02 tomcat
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1973b025df8f tomcat "catalina.sh run" 2 days ago Up 35 minutes 0.0.0.0:49154->8080/tcp, :::49154->8080/tcp tomcat02
cabdc1bbda8e tomcat "catalina.sh run" 2 days ago Up 35 minutes 0.0.0.0:49153->8080/tcp, :::49153->8080/tcp tomcat01
[root@localhost ~]#
(2)tomcat01尝试连接tomcat02
[root@localhost ~]# docker exec -it tomcat01 ping tomcat02
ping: tomcat02: Name or service not known
[root@localhost ~]#
(3)网络连通-------docker connect命令
[root@localhost ~]# docker network connect dong_net tomcat01
[root@localhost ~]# docker network connect dong_net tomcat02
[root@localhost ~]# docker exec -it tomcat01 ping tomcat02
PING tomcat02 (192.168.0.3) 56(84) bytes of data.
64 bytes from tomcat02.dong_net (192.168.0.3): icmp_seq=1 ttl=64 time=0.111 ms
64 bytes from tomcat02.dong_net (192.168.0.3): icmp_seq=2 ttl=64 time=0.070 ms
...
[root@localhost ~]#
?说明:
dong_net为自定义的网络。
|