《Docker容器管理与应用项目教程 任务拓展训练答案 项目三.docx》由会员分享,可在线阅读,更多相关《Docker容器管理与应用项目教程 任务拓展训练答案 项目三.docx(2页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、一、任务3.1拓展训练1 .在docker服务上,删除默认的网桥设备dockerOo1)关闭 dockerOrootlocalhost # ip link set dev dockerO down2)删除 dockerOrootlocalhost # brctl delbr dockerO2 .创建一个新的网桥,名称为docket,网络为172.2000/16。1)创建网桥rootlocalhost # 3 .使用alpine:latest镜像创建2个容器,名称分别为netl和net2。都连接在dockerl 网桥下。1)创建容器rootlocalhost # docker run -name
2、=netl -itd -network=dockerl alpine /bin/shrootlocalhost # docker run -name=net2 -itd -network=dockerl alpine /bin/sh4 .查看Docke门接口的IP地址,查看dockerl网桥的Veth虚拟网卡。1) IP地址rootlocalhost # ip add2) Veth虚拟网卡rootlocalhost # brctl show bridge name bridge id STP enabled interfaces br-91e65bf9756f8000.0242ec41dcfe
3、 no veth0e78368vethfa210695 .查看netl和net2容器的IP地址,进入netl容器,测试与net2容器的连通性。1) netl容器IP地址rootlocalhost # docker exec -ti netl /bin/sh/# ip addr1: Io: mtu 65536 qdisc noqueue state UNKNOWN qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00valid_lft forever preferred_lft foreverinet6 :1/128 sco
4、pe host valid_lft forever preferredjft forever 9: ethOiflO: mtu 1500 qdiscnoqueue state UPlink/ether 02:42:ac:14:00:02 brd ff:ff:ff:ff:ff:ffvalidjft forever preferred_lft foreverinet6 fe80:42:acff:fel4:2/64 scope linkvalidjft forever preferred_lft forever2) net2容器IP地址rootlocalhost # docker exec -ti
5、net2 /bin/sh/# ip addrIo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00validjft forever preferred_lft foreverinet6 :1/128 scope hostvalidjft forever preferred_lft foreverethOifl2: mtu 1500qdisc noqueue state UPlink/ether 02:42:ac:14:00:03 brdval
6、idjft forever preferred_lft foreverinet6 fe80:42:acff:fel4:3/64 scope linkvalidjft forever preferred_lft forever3)联通性测试PING 172.20.0.2 (172.20.0.2): 56 data bytes64 bytes from 172.20.0.2: seq=0 ttl=64 time=0.294 ms二、任务3.2拓展训练L使用克隆构建2台带有Docker服务的主机,主机名称为DockerOl和Docker02o2.在Docker。1和Docker02上部署Macvla
7、n网络,网络地址为172.16.10.0/16,默 认网关是dockerOl 仓建 Macvlan 网络-d macvlan-d macvlanrootdockerl # docker network create172.16.10.1 -o172.16.10.1 -oparent=eth0 mac 1subnet 172.16.10.0/24 gatewaydocker02 创建 Macvlan 网络rootdocker2 # docker network createsubnet 172.16.10.0/24 gateway 172.16.10.1 -o parent=eth0 mac 1
8、3 .基于Macvlan网络,使用alpinedatest镜像,分别在DockerOl和Docker02上部 署容器,指定 IP 地址分别为 dockerOl创建容器rootdockerl # docker run -itd -ip 172.16.10.10 networkmacl alpine1) docker02创建容器rootdockerl # docker run -itd ip 172.16.10.20 network macl alpine4 .测试Dockerl和Docker2两台主机上容器的连通性。1) dockerl 访问 docker2rootdockerl # docker exec -it 041 /bin/shPING 172.16.10.20(172.16.10.20): 56 data bytes64 bytes from 172.16.10.20: seq=0 ttl=64 time=0.851 ms