mount 命令查看挂载信息
- /etc/hosts, /etc/hostname, /etc/resolve.conf 是临时的,只是在运行容器时保留,docker commit不会被提交
root@gitlab:/# mount |grep "/etc"
/dev/vdb1 on /etc/gitlab type ext4 (rw,relatime,data=ordered)
/dev/vda1 on /etc/resolv.conf type ext4 (rw,relatime,data=ordered)
/dev/vda1 on /etc/hostname type ext4 (rw,relatime,data=ordered)
/dev/vda1 on /etc/hosts type ext4 (rw,relatime,data=ordered)
检查容器访问外部网络
$ sudo sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
$ sudo sysctl -w net.ipv4.ip_forward=1 # 打开
查看宿主机nat表上POSTROUTING链规则
iptables -t nat -nvL POSTROUTING
Docker自定义网桥
- 默认docker0网桥,在Docker服务启动时可以使用-b BRIDGE 来指定使用的网桥
- 停止docker服务,删除docker0网桥
$ systemctl stop docker
$ ip link set dev docker0 down
$ brctl delbr docker0
- 创建一个网桥bridge0
$ brctl addbr bridge0
$ ip addr add 192.168.5.1/24 dev bridge0
$ ip link set dev bridge0 up
- 查看网桥并启动
$ ip addr show bridge0
$ echo 'DOCKER_OPTS="-b=bridge0"' >> /etc/defalut/docker
$ sudo systemctl start docker