docker使用宿主機網段

#####配置網橋docker0linux

# cat /etc/sysconfig/network-scripts/ifcfg-docker0docker

DEVICE="docker0"
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=static
STP=yes
IPADDR=192.168.1.11
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

# cat /etc/sysconfig/network-scripts/ifcfg-eno16777736網絡

TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=c45684a5-301a-4c71-97bd-530c313df1b5
DEVICE=eno16777736
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
BRIDGE=docker0        #添加此行

# ip aoop

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:75:9d:a2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.107/24 brd 192.168.1.255 scope global dynamic eno16777736
       valid_lft 6985sec preferred_lft 6985sec
    inet6 fe80::20c:29ff:fe75:9da2/64 scope link
       valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
    link/ether 0e:bf:63:7d:e4:49 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.11/24 brd 192.168.1.255 scope global docker0
       valid_lft forever preferred_lft forever

#####配置docker測試

# cat /etc/sysconfig/docker|grep -v ^$|grep -v ^# OPTIONS='--selinux-enabled --fixed-cidr=192.168.1.128/25 -b=docker0' #修改此行 DOCKER_CERT_PATH=/etc/docker3d

# systemctl restart docker.servicerest

#####測試docker網絡code

# docker run -d --name=docker1 busybox sleep 100000ip

d87f48c6526b7c4ad4ec1b59808454094a62fdfa8a0ab64582e08b0797ca0c2a

# docker exec -it d87f48c6526b shci

/ # ls
bin   dev   etc   home  proc  root  run   sys   tmp   usr   var
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue
    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
17: eth0@if18: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
    link/ether 02:42:c0:a8:01:80 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.128/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:c0ff:fea8:180/64 scope link
       valid_lft forever preferred_lft forever
/ # ping 192.168.1.128
PING 192.168.1.128 (192.168.1.128): 56 data bytes
64 bytes from 192.168.1.128: seq=0 ttl=64 time=0.047 ms
64 bytes from 192.168.1.128: seq=1 ttl=64 time=0.077 ms
^C
--- 192.168.1.128 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.047/0.062/0.077 ms
/ # ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: seq=0 ttl=64 time=6.017 ms
^C
--- 192.168.1.1 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 6.017/6.017/6.017 ms
/ # ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: seq=0 ttl=64 time=2.177 ms
^C
--- 192.168.1.1 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 2.177/2.177/2.177 ms
/ # ping 192.168.1.11
PING 192.168.1.11 (192.168.1.11): 56 data bytes
64 bytes from 192.168.1.11: seq=0 ttl=64 time=0.210 ms
^C
--- 192.168.1.11 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0.210/0.210/0.210 ms
/ # ping 192.168.1.105
PING 192.168.1.105 (192.168.1.105): 56 data bytes
64 bytes from 192.168.1.105: seq=0 ttl=64 time=0.523 ms
^C
相關文章
相關標籤/搜索