Docker 单主机网络

这篇文章主要简述 docker 中的 bridge 网络驱动是如何工作的。

1. 测试一,veth1 (ns1) — veth2 (ns2)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# create ns1, ns2
ip netns add ns1
ip netns add ns2

# create veth1, veth2
ip link add veth1 type veth peer name veth2

# set veth1 for ns1, set veth2 for ns2
ip link set dev veth1 netns ns1
ip link set dev veth2 netns ns2

# set veth1 ip, set veth2 ip
ip netns exec ns1 ip addr add 172.16.0.1/24 dev veth1
ip netns exec ns2 ip addr add 172.16.0.2/24 dev veth2

# set veth1 up, set veth2 up
ip netns exec ns1 ip link set dev veth1 up
ip netns exec ns2 ip link set dev veth2 up

# show ip address
ip netns exec ns1 ip addr
ip netns exec ns2 ip addr

# test for ping 
ip netns exec ns1 ping 172.16.0.2
ip netns exec ns2 ping 172.16.0.1

# recovery all setting 
ip netns delete ns1
ip netns delete ns2

2. 测试二,veth0 (bridge0) — veth1 (ns1)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# create ns1
ip netns add ns1

# create veth0, veth1
ip link add veth0 type veth peer name veth1

# create bridge0
ip link add bridge0 type bridge

# set veth1 for ns1
ip link set dev veth1 netns ns1

# set veth0 for bridge0
ip link set dev veth0 master bridge0

# set veth0 ip address
ip addr add 172.16.0.1/24 dev veth0

# set bridge0 ip address
ip addr add 172.16.0.0/24 dev bridge0

# set veth1 ip address
ip netns exec ns1 ip addr add 172.16.0.2/24 dev veth1

# set veth0, veth1, bridge0 up
ip link set dev veth0 up
ip link set dev bridge0 up
ip netns exec ns1 ip link set dev veth1 up

# delete veth0 route
ip route del 172.16.0.0/24 dev veth0

# show ip address
ip addr
ip netns exec ns1 ip addr

# test for ping 
ping 172.16.0.2
ip netns exec ns1 ping 172.16.0.1

# recovery all setting 
ip netns del ns1
ip link del bridge0

搭建 Istio 源码调试环境

1. 前置条件

  • 安装 docker,必须配置 docker 代理,否则 build 失败。 参考
  • 下载 istio 源码。
  • 安装 godlv 工具。参考

2. 设置环境变量

1
2
3
4
5
6
7
8
# docker 地址
export HUB="docker.io/youwillsee"

# istio 的源码目录
export ISTIO=/root/code/istio

# docker 的 tag
export TAG=1.17-debug

3. build istio

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 构建 debug 的版本,会输出在 out 目录下
make DEBUG=1 build

# 构建 debug 的版本,推到本地的 docker 中
make DEBUG=1 docker

# 推送到远端的 docker 中
make docker.push

# 清理
make clean

参考

设置 Docker 代理

1. 配置 docker 代理

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 创建配置目录
mkdir -p /etc/systemd/system/docker.service.d

# 创建配置文件
vim /etc/systemd/system/docker.service.d/http-proxy.conf

# 配置文件内容
[Service]
Environment="HTTP_PROXY=http://ooooo:10800"
Environment="HTTPS_PROXY=http://ooooo:10800"

# 重启 docker
systemctl daemon-reload && systemctl restart docker

# 查看配置是否生效
systemctl show --property=Environment docker