Docker命令
1.命令格式:
docker run -it --name mydocker1 [image1] bash #对image1取个别名为mydocker1
docker run -it --link mydocker1:mydocker1 [image2] bash 把两个image连通,使得image1和image2可以互相通讯
2.命令功能:
把两个container相互连通通信
3.命令参数:
-it --name 先对第一个image1取名称
-it --link 连接到第一个image,相互之间可以通讯
4.命令实例:
首先打开一个窗口输入以下命令,打开一个docker窗口1
[root@docker ~]# docker run -it --name node1 node bash
root@f2765d5fd9c8:/#
再次打开另一个窗口2,输入以下命令:
[root@docker ~]# docker run -it --link node1:node1 node bash
root@e85d11098482:/#
在第二个docker窗口下输入以下命令:
root@e85d11098482:/# ping node1 显示node1的ip地址是172.16.0.16
PING node1 (172.17.0.16): 56 data bytes
64 bytes from 172.17.0.16: icmp_seq=0 ttl=64 time=0.110 ms
64 bytes from 172.17.0.16: icmp_seq=1 ttl=64 time=0.073 ms
64 bytes from 172.17.0.16: icmp_seq=2 ttl=64 time=0.075 ms
64 bytes from 172.17.0.16: icmp_seq=3 ttl=64 time=0.094 ms
^C--- node1 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.073/0.088/0.110/0.000 ms
在第一个docker窗口下输入以下命令,查看该窗口的IP地址正是node1的IP地址
root@f2765d5fd9c8:/# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
34: eth0@if35: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:10 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.16/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:10/64 scope link
valid_lft forever preferred_lft forever