- 尚硅谷大数据技术-教程-学习路线-笔记汇总表【课程资料下载】
- 视频地址:尚硅谷Docker实战教程(docker教程天花板)_哔哩哔哩_bilibili
- 尚硅谷Docker实战教程-笔记01【基础篇,Docker理念简介、官网介绍、平台入门图解、平台架构图解】
- 尚硅谷Docker实战教程-笔记02【基础篇,Docker安装、镜像加速器配置】
- 尚硅谷Docker实战教程-笔记03【基础篇,Docker常用命令】
- 尚硅谷Docker实战教程-笔记04【基础篇,Docker镜像】
尚硅谷Docker实战教程-笔记05【基础篇,Docker本地镜像发布到阿里云与私有库】
尚硅谷Docker实战教程-笔记06【基础篇,Docker容器数据卷】
尚硅谷Docker实战教程-笔记07【基础篇,Docker常规安装简介】
尚硅谷Docker实战教程-笔记08【高级篇,Docker复杂安装详说】
尚硅谷Docker实战教程-笔记09【高级篇,DockerFile解析】
尚硅谷Docker实战教程-笔记10【高级篇,Docker微服务实战】
尚硅谷Docker实战教程-笔记11【高级篇,Docker网络】
尚硅谷Docker实战教程-笔记12【高级篇,Docker-compose容器编排】
尚硅谷Docker实战教程-笔记13【高级篇,Docker轻量级可视化工具Portainer】
尚硅谷Docker实战教程-笔记14【高级篇,Docker容器监控之CAdvisor+InfluxDB+Granfana、Docker终章总结】
目录
2.高级篇(大厂进阶)
4.Docker网络
P066【66_docker network简介】08:46
P067【67_docker network常用命令】04:17
P068【68_docker network能干嘛】03:09
P069【69_docker network网络模式有几种】03:48
P070【70_docker network底层ip和容器映射变化】06:16
P071【71_docker network之bridge】13:13
P072【72_docker network之host】08:19
P073【73_docker network之none】02:29
P074【74_docker network之container】07:15
P075【75_docker network之自定义网络上集】03:12
P076【76_docker network之自定义网络中集】03:54
P077【77_docker network之自定义网络下集】04:17
2.高级篇(大厂进阶)
4.Docker网络
P066【66_docker network简介】08:46
桥接:虚拟机直接连接外部的物理网络,主机起到了网桥的作用,虚拟机可以直接访问外网,并且是透明的。
[root@node001 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:45:80:b6 brd ff:ff:ff:ff:ff:ff
inet 192.168.10.101/24 brd 192.168.10.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::363b:8659:c323:345d/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:1c:3c:a9 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:1c:3c:a9 brd ff:ff:ff:ff:ff:ff
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:ea:3c:8d:47 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
[root@node001 ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ea:3c:8d:47 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.101 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::363b:8659:c323:345d prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:45:80:b6 txqueuelen 1000 (Ethernet)
RX packets 1347 bytes 110170 (107.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1885 bytes 539241 (526.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 84 bytes 9492 (9.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 84 bytes 9492 (9.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:1c:3c:a9 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@node001 ~]#
P067【67_docker network常用命令】04:17
[root@node001 ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
15e7f7fc3ef3 bridge bridge local
baa791142a49 host host local
f1c56a47c312 none null local
[root@node001 ~]# docker network --help
Usage: docker network COMMAND
Manage networks
Commands:
connect Connect a container to a network
create Create a network
disconnect Disconnect a container from a network
inspect Display detailed information on one or more networks
ls List networks
prune Remove all unused networks
rm Remove one or more networks
Run 'docker network COMMAND --help' for more information on a command.
[root@node001 ~]# docker network create aa_network
6396717447f3bdd837e532aa3a43a4f6d119c6ab11ad82dd3283cab6ce8e1ff2
[root@node001 ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
6396717447f3 aa_network bridge local
15e7f7fc3ef3 bridge bridge local
baa791142a49 host host local
f1c56a47c312 none null local
[root@node001 ~]# docker network rm aa_network
aa_network
[root@node001 ~]# docker network inspect bridge
[
{
"Name": "bridge",
"Id": "15e7f7fc3ef30852ccd8188e6efc6c7f1112ad72ebd48b2db210e25318d40b01",
"Created": "2023-07-10T10:00:47.863580701+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
[root@node001 ~]#
P068【68_docker network能干嘛】03:09
docker network 作用:
- 容器间的互联和通信以及端口映射
- 容器IP变动时候可以通过服务名直接网络通信而不受到影响
P069【69_docker network网络模式有几种】03:48
P070【70_docker network底层ip和容器映射变化】06:16
结论:docker容器内部的ip是有可能会发生改变的。
[root@node001 ~]# docker run -it --name u1 ubuntu bash
docker: Error response from daemon: Conflict. The container name "/u1" is already in use by container "191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
[root@node001 ~]# docker run -it --name u1 ubuntu /bin/bash
docker: Error response from daemon: Conflict. The container name "/u1" is already in use by container "191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
[root@node001 ~]#
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@node001 ~]# docker run -it --name u2 ubuntu /bin/bash
root@a3a2d265c8d0:/# [root@node001 ~]#
[root@node001 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosjava8 1.5 0f64bc97e953 2 days ago 1.27GB
vluubuntu 1.2 a1ed6fe2f61e 9 days ago 118MB
node001:5000/vluubuntu 1.2 a1ed6fe2f61e 9 days ago 118MB
ubuntu 1.2 7295d0d3bc7e 9 days ago 118MB
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu 1.3 079bf1275a8a 10 days ago 185MB
atguigu/ubuntu 3.7 7b40f602c178 10 days ago 72.8MB
hello-world <none> 9c7a54a9a43c 2 months ago 13.3kB
tomcat latest fb5657adc892 18 months ago 680MB
mysql 5.7 c20987f18b13 18 months ago 448MB
registry latest b8604a3fe854 20 months ago 26.2MB
ubuntu latest ba6acccedd29 21 months ago 72.8MB
hello-world latest feb5d9fea6a5 21 months ago 13.3kB
centos latest 5d0da3dc9764 22 months ago 231MB
redis 6.0.8 16ecd2772934 2 years ago 104MB
billygoo/tomcat8-jdk8 latest 30ef4019761d 4 years ago 523MB
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3a2d265c8d0 ubuntu "/bin/bash" About a minute ago Up About a minute u2
[root@node001 ~]# docker start u1
u1
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3a2d265c8d0 ubuntu "/bin/bash" 2 minutes ago Up 2 minutes u2
191b846e7af7 ubuntu "/bin/bash" 7 days ago Up 4 seconds u1
[root@node001 ~]# docker inspect u1
[
{
"Id": "191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266",
"Created": "2023-07-03T03:13:52.588573071Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 78941,
"ExitCode": 0,
"Error": "",
"StartedAt": "2023-07-10T03:01:21.625402696Z",
"FinishedAt": "2023-07-03T03:40:14.88557386Z"
},
"Image": "sha256:ba6acccedd2923aee4c2acc6a23780b14ed4b8a5fa4e14e252a23b846df9b6c1",
"ResolvConfPath": "/var/lib/docker/containers/191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266/hostname",
"HostsPath": "/var/lib/docker/containers/191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266/hosts",
"LogPath": "/var/lib/docker/containers/191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266/191b846e7af7cfa2562ad28b18c43530264bf38a87d398654ebea49d40355266-json.log",
"Name": "/u1",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/tmp/myHostData:/tmp/myDockerData:ro"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"ConsoleSize": [
25,
159
],
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": true,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": [
"label=disable"
],
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": [],
"BlkioDeviceWriteBps": [],
"BlkioDeviceReadIOps": [],
"BlkioDeviceWriteIOps": [],
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": null,
"ReadonlyPaths": null
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/43f6b0e9374010860528d0c061a9174f201391e9b2d9075fc466dc87a14efcdb-init/diff:/var/lib/docker/overlay2/f9254c3773e2c54c48ab593bcd84c8af0f7b65955f4d04fc08205a994258d983/diff",
"MergedDir": "/var/lib/docker/overlay2/43f6b0e9374010860528d0c061a9174f201391e9b2d9075fc466dc87a14efcdb/merged",
"UpperDir": "/var/lib/docker/overlay2/43f6b0e9374010860528d0c061a9174f201391e9b2d9075fc466dc87a14efcdb/diff",
"WorkDir": "/var/lib/docker/overlay2/43f6b0e9374010860528d0c061a9174f201391e9b2d9075fc466dc87a14efcdb/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/tmp/myHostData",
"Destination": "/tmp/myDockerData",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "191b846e7af7",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Image": "ubuntu",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "fc0293e83763fea837ea4177961eeb0d8d86e7ed9293fbb5c21cad3e82025451",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/fc0293e83763",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "230dae8dc1c61af9a4280253525e6443e92dbabaa675299a3cb64cc67d84eead",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:03",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "15e7f7fc3ef30852ccd8188e6efc6c7f1112ad72ebd48b2db210e25318d40b01",
"EndpointID": "230dae8dc1c61af9a4280253525e6443e92dbabaa675299a3cb64cc67d84eead",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:03",
"DriverOpts": null
}
}
}
}
]
[root@node001 ~]# docker inspect u1 | tail -n 20
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "15e7f7fc3ef30852ccd8188e6efc6c7f1112ad72ebd48b2db210e25318d40b01",
"EndpointID": "230dae8dc1c61af9a4280253525e6443e92dbabaa675299a3cb64cc67d84eead",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:03",
"DriverOpts": null
}
}
}
}
]
[root@node001 ~]# docker inspect u2 | tail -n 20
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "15e7f7fc3ef30852ccd8188e6efc6c7f1112ad72ebd48b2db210e25318d40b01",
"EndpointID": "07dfc1689c6be633242e6c25d9ac540c38dbdfd5e418fd55b5e13b143a6745ec",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
[root@node001 ~]# docker rm -f u2
u2
[root@node001 ~]# docker run -it --name u3 ubuntu bash
root@32e53de0224b:/# [root@node001 ~]#
[root@node001 ~]# docker inspect u3 | tail -n 20
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "15e7f7fc3ef30852ccd8188e6efc6c7f1112ad72ebd48b2db210e25318d40b01",
"EndpointID": "03f56e1422d24b8404e2bc93ef85b1f0676279d7c761d16aac7d39c30116d2cc",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
[root@node001 ~]# docker network create bb_network
c6cc76c12f4f793e4488364a462dfaf1be40b6c58f35548e95e8a6b0b9f2cd59
[root@node001 ~]#
P071【71_docker network之bridge】13:13
[root@node001 ~]# docker run -d -p 8081:8080 --name tomcat81 billygoo/tomcat8-jdk8
612acb85417b79180b9dda0aee5d3435a02d8f75d9017dc5c58b48f298b03330
[root@node001 ~]# docker run -d -p 8082:8080 --name tomcat82 billygoo/tomcat8-jdk8
c1c3cceb68e2e4ac43d95d8fd5173895801b61026dcfd7fb9cfc2688341b8437
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c1c3cceb68e2 billygoo/tomcat8-jdk8 "catalina.sh run" 21 seconds ago Up 18 seconds 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp tomcat82
612acb85417b billygoo/tomcat8-jdk8 "catalina.sh run" 46 seconds ago Up 44 seconds 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat81
22ddf65b567c ubuntu "bash" 13 minutes ago Up 13 minutes u2
32e53de0224b ubuntu "bash" 19 minutes ago Up 19 minutes u3
191b846e7af7 ubuntu "/bin/bash" 7 days ago Up 23 minutes u1
[root@node001 ~]# docker stop u1 u2 u3
u1
u2
u3
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c1c3cceb68e2 billygoo/tomcat8-jdk8 "catalina.sh run" 45 seconds ago Up 42 seconds 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp tomcat82
612acb85417b billygoo/tomcat8-jdk8 "catalina.sh run" About a minute ago Up About a minute 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat81
[root@node001 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:45:80:b6 brd ff:ff:ff:ff:ff:ff
inet 192.168.10.101/24 brd 192.168.10.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::363b:8659:c323:345d/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:1c:3c:a9 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:1c:3c:a9 brd ff:ff:ff:ff:ff:ff
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ea:3c:8d:47 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:eaff:fe3c:8d47/64 scope link
valid_lft forever preferred_lft forever
13: br-c6cc76c12f4f: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:60:73:7a:a9 brd ff:ff:ff:ff:ff:ff
inet 172.19.0.1/16 brd 172.19.255.255 scope global br-c6cc76c12f4f
valid_lft forever preferred_lft forever
17: veth69f6c0e@if16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 92:77:13:19:88:b9 brd ff:ff:ff:ff:ff:ff link-netnsid 3
inet6 fe80::9077:13ff:fe19:88b9/64 scope link
valid_lft forever preferred_lft forever
19: vetha0b2bcb@if18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 6e:91:00:5d:6f:b6 brd ff:ff:ff:ff:ff:ff link-netnsid 4
inet6 fe80::6c91:ff:fe5d:6fb6/64 scope link
valid_lft forever preferred_lft forever
[root@node001 ~]# docker exec -it tomcat81 bash
root@612acb85417b:/usr/local/tomcat# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
16: eth0@if17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:05 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.5/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
root@612acb85417b:/usr/local/tomcat# read escape sequence
[root@node001 ~]# docker exec -it tomcat82 bash
root@c1c3cceb68e2:/usr/local/tomcat# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
18: eth0@if19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:06 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.6/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
root@c1c3cceb68e2:/usr/local/tomcat# read escape sequence
[root@node001 ~]#
P072【72_docker network之host】08:19
[root@node001 ~]# docker start tomcat81
tomcat81
[root@node001 ~]# docker start tomcat82
tomcat82
[root@node001 ~]# docker run -d -p 8083:8080 --network host --name tomcat83 billygoo/tomcat8-jdk8
WARNING: Published ports are discarded when using host network mode
f6336ffb274c54cb86b727195f878b559b8f6e8aa6f6fb734c75b24d7b20099c
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f6336ffb274c billygoo/tomcat8-jdk8 "catalina.sh run" 5 seconds ago Up 3 seconds tomcat83
c1c3cceb68e2 billygoo/tomcat8-jdk8 "catalina.sh run" 4 hours ago Up 48 seconds 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp tomcat82
612acb85417b billygoo/tomcat8-jdk8 "catalina.sh run" 4 hours ago Up 52 seconds 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat81
[root@node001 ~]# docker rm -f tomcat83
tomcat83
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c1c3cceb68e2 billygoo/tomcat8-jdk8 "catalina.sh run" 4 hours ago Up 3 minutes 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp tomcat82
612acb85417b billygoo/tomcat8-jdk8 "catalina.sh run" 4 hours ago Up 3 minutes 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat81
[root@node001 ~]# docker run -d --network host --name tomcat83 billygoo/tomcat8-jdk8
bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b
[root@node001 ~]# docker inspect tomcat83
[
{
"Id": "bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b",
"Created": "2023-07-10T07:25:41.756619244Z",
"Path": "catalina.sh",
"Args": [
"run"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 29365,
"ExitCode": 0,
"Error": "",
"StartedAt": "2023-07-10T07:25:42.079612342Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:30ef4019761d4aee397841d0b4291a928a4816745e2eba2ead83f1d2cf64d42a",
"ResolvConfPath": "/var/lib/docker/containers/bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b/hostname",
"HostsPath": "/var/lib/docker/containers/bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b/hosts",
"LogPath": "/var/lib/docker/containers/bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b/bf2b920ad4d5e29e0c664ed9c312cb8abc17b85925f2defb7fe340bc896a4c6b-json.log",
"Name": "/tomcat83",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "host",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"ConsoleSize": [
30,
159
],
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": [],
"BlkioDeviceWriteBps": [],
"BlkioDeviceReadIOps": [],
"BlkioDeviceWriteIOps": [],
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/629599bb853e3e9eebfe87c61dd999d46cbcfc187f29505a3672afa0a75ff956-init/diff:/var/lib/docker/overlay2/9842fc8b9968299b96b9d8c1eb56096313ac3d3b50930cc7c262ff86a3d31e82/diff:/var/lib/docker/overlay2/7c4eb16163030abb5a2df0b7aac0a4047e03fad852cef52dffe3ece7f47a2c62/diff:/var/lib/docker/overlay2/534dcd05dc0c4c5ac338d39ef770a7b87ec3ad0ae4ca8f84570f28cc24cafb60/diff:/var/lib/docker/overlay2/d0fd9f89b30193ea1d8715e4a16956ad9f6b5eadcd3e3ba18bacb3f78bcc7ced/diff:/var/lib/docker/overlay2/268ce34b7cafa7ebe9d4dd9cc38d505d2c1fa43132c84c50ede21a5cc4f41981/diff:/var/lib/docker/overlay2/10ae0293114a7166a84b7c0cf5e0b1f8056bca9d819154fc78475563b9021645/diff:/var/lib/docker/overlay2/2b04040394297975a4ed6124b0886ae08427656f2a0a596ace8d6902a4756c82/diff:/var/lib/docker/overlay2/6bc48a69da1f07ee2209d121ce1fab14b8ab4dc897fb0cdd3ca9abd507f0b3b6/diff:/var/lib/docker/overlay2/4f30323fd41675a567ebd4a4484bcdd5a5fed81c92a2f96ab28bea370244800f/diff:/var/lib/docker/overlay2/d089666b37a1f0650501fdd6ecdf9971ec871dbe4b1ffde16c471aae7284154e/diff:/var/lib/docker/overlay2/464427884ca315d81c9ba390bb0a1d095599c04e12dd71e626dcd7335d0fed51/diff:/var/lib/docker/overlay2/893d0d8ac70514a6a52ab778a2c1e4f027f9a52438cdafa60953057ad06a2a84/diff:/var/lib/docker/overlay2/1f631e4437002ddab9e06016c026fdece3744a3817284da253433724050ddeff/diff",
"MergedDir": "/var/lib/docker/overlay2/629599bb853e3e9eebfe87c61dd999d46cbcfc187f29505a3672afa0a75ff956/merged",
"UpperDir": "/var/lib/docker/overlay2/629599bb853e3e9eebfe87c61dd999d46cbcfc187f29505a3672afa0a75ff956/diff",
"WorkDir": "/var/lib/docker/overlay2/629599bb853e3e9eebfe87c61dd999d46cbcfc187f29505a3672afa0a75ff956/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "node001",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/tomcat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64",
"JAVA_VERSION=8u171",
"JAVA_DEBIAN_VERSION=8u171-b11-1~deb9u1",
"CA_CERTIFICATES_JAVA_VERSION=20170531+nmu1",
"CATALINA_HOME=/usr/local/tomcat",
"TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib",
"LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib",
"OPENSSL_VERSION=1.1.0f-3+deb9u2",
"GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23",
"TOMCAT_MAJOR=8",
"TOMCAT_VERSION=8.0.53",
"TOMCAT_SHA512=cd8a4e48a629a2f2bb4ce6b101ebcce41da52b506064396ec1b2915c0b0d8d82123091242f2929a649bcd8b65ecf6cd1ab9c7d90ac0e261821097ab6fbe22df9",
"TOMCAT_TGZ_URLS=https://www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz \thttps://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz \thttps://www.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz \thttps://archive.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz",
"TOMCAT_ASC_URLS=https://www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc \thttps://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc \thttps://www.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc \thttps://archive.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc"
],
"Cmd": [
"catalina.sh",
"run"
],
"Image": "billygoo/tomcat8-jdk8",
"Volumes": null,
"WorkingDir": "/usr/local/tomcat",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "7591a0130844df2007694034069cfaf3fa79bc78231b9ae9009018da96a5531e",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/default",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"host": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "baa791142a49a66e391e60263e60a188bdc7e27072119fd585436e281d91160f",
"EndpointID": "cbbf729509f1984fc3eb556ad34d37f17915d0cd41d1a47ebad5326637ff3583",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
[root@node001 ~]# docker exec -it tomcat83 bash
root@node001:/usr/local/tomcat#
P073【73_docker network之none】02:29
[root@node001 ~]# docker run -d -p 8084:8080 --network none --name tomcat84 billygoo/tomcat8-jdk8
6f3e8c545791a435a9b3dbcd8ec1c0fb051daa386ea4e3513e775c1623d95046
[root@node001 ~]# docker inspect tomcat84 | tail -n 20
"Networks": {
"none": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "f1c56a47c3128e398257a61ffa51451a2532f7dbe34336a5169e4a16f770f0a2",
"EndpointID": "ca7ed125ec6466a372ea3dc9c5d00b0b5d99a1680966e0830f19a3b187606cc8",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6f3e8c545791 billygoo/tomcat8-jdk8 "catalina.sh run" 12 minutes ago Up 12 minutes tomcat84
bf2b920ad4d5 billygoo/tomcat8-jdk8 "catalina.sh run" 31 minutes ago Up 31 minutes tomcat83
c1c3cceb68e2 billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up 35 minutes 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp tomcat82
612acb85417b billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up 36 minutes 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat81
[root@node001 ~]# docker exec -it tomcat84 bash
root@6f3e8c545791:/usr/local/tomcat# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
root@6f3e8c545791:/usr/local/tomcat# read escape sequence
[root@node001 ~]#
P074【74_docker network之container】07:15
container⽹络模式
新建的容器和已经存在的一个容器共享一个网络ip配置而不是和宿主机共享。新创建的容器不会创建自己的网卡,配置自己的IP,而是和一个指定的容器共享IP、端口范围等。同样,两个容器除了网络方面,其他的如文件系统、进程列表等还是隔离的。
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6f3e8c545791 billygoo/tomcat8-jdk8 "catalina.sh run" 18 minutes ago Up 18 minutes tomcat84
bf2b920ad4d5 billygoo/tomcat8-jdk8 "catalina.sh run" 37 minutes ago Up 37 minutes tomcat83
c1c3cceb68e2 billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up 41 minutes 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp tomcat82
612acb85417b billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up 41 minutes 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat81
[root@node001 ~]# docker run -d -p 8085:8080 --name tomcat85 billygoo/tomcat8-jdk8
439b7efdb024b4b359a4a33f31620c01128828923813b5669d233172d8602965
[root@node001 ~]# docker run -d -p 8086:8080 --network container:tomcat85 --name tomcat86 billygoo/tomcat8-jdk8
docker: Error response from daemon: conflicting options: port publishing and the container type network mode.
See 'docker run --help'.
[root@node001 ~]# docker rm -f tomcat85
tomcat85
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6f3e8c545791 billygoo/tomcat8-jdk8 "catalina.sh run" 21 minutes ago Up 21 minutes tomcat84
bf2b920ad4d5 billygoo/tomcat8-jdk8 "catalina.sh run" 41 minutes ago Up 41 minutes tomcat83
c1c3cceb68e2 billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up 45 minutes 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp tomcat82
612acb85417b billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up 45 minutes 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat81
[root@node001 ~]# docker run -it --name alpine1 alpine /bin/sh
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
59bf1c3509f3: Pull complete
Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
Status: Downloaded newer image for alpine:latest
/ # ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
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
13: eth0@if14: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
link/ether 02:42:ac:11:00:04 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.4/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
/ # exit
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64ffeaad19d9 alpine "/bin/sh" 15 minutes ago Up 15 minutes alpine2
6f3e8c545791 billygoo/tomcat8-jdk8 "catalina.sh run" 40 minutes ago Up 40 minutes tomcat84
bf2b920ad4d5 billygoo/tomcat8-jdk8 "catalina.sh run" 59 minutes ago Up 59 minutes tomcat83
c1c3cceb68e2 billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up About an hour 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp tomcat82
612acb85417b billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up About an hour 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat81
[root@node001 ~]#
[root@node001 ~]# docker run -it --network container:alpine1 --name alpine2 alpine /bin/sh
/ # ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
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
13: eth0@if14: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
link/ether 02:42:ac:11:00:04 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.4/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
/ # exit
[root@node001 ~]#
P075【75_docker network之自定义网络上集】03:12
[root@node001 ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
c6cc76c12f4f bb_network bridge local
616bcbc5cc80 bridge bridge local
baa791142a49 host host local
f1c56a47c312 none null local
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6f3e8c545791 billygoo/tomcat8-jdk8 "catalina.sh run" 48 minutes ago Up 48 minutes tomcat84
bf2b920ad4d5 billygoo/tomcat8-jdk8 "catalina.sh run" About an hour ago Up About an hour tomcat83
c1c3cceb68e2 billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up About an hour 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp tomcat82
612acb85417b billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up About an hour 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat81
[root@node001 ~]#
P076【76_docker network之自定义网络中集】03:54
[root@node001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6f3e8c545791 billygoo/tomcat8-jdk8 "catalina.sh run" 58 minutes ago Up 58 minutes tomcat84
bf2b920ad4d5 billygoo/tomcat8-jdk8 "catalina.sh run" About an hour ago Up About an hour tomcat83
c1c3cceb68e2 billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up About an hour 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp tomcat82
612acb85417b billygoo/tomcat8-jdk8 "catalina.sh run" 5 hours ago Up About an hour 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat81
[root@node001 ~]# docker exec -it tomcat81 bash
root@612acb85417b:/usr/local/tomcat# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
7: eth0@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
root@612acb85417b:/usr/local/tomcat# ping 172.17.0.3
PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.591 ms
64 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.099 ms
[root@node001 ~]# docker exec -it tomcat82 bash
root@c1c3cceb68e2:/usr/local/tomcat# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
9: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
root@c1c3cceb68e2:/usr/local/tomcat# ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.708 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.136 ms
64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.095 ms