# blade create docker network

## 介绍

容器内网络实验场景，同基础资源的网络场景

## 命令

支持的网络场景命令如下：

* `blade create docker network delay` 容器网络延迟，同 \[blade create network delay]\(blade create network delay.md)
* `blade create docker network loss` 容器网络丢包，同 \[blade create network loss]\(blade create network loss.md)
* `blade create docker network dns` 容器内域名访问异常，同 \[blade create network dns]\(blade create network dns.md)

## 参数

除了上述基础场景各自所需的参数外，在 docker 环境下，还支持的参数如下：

```
--container-id string      目标容器 ID
--docker-endpoint string   Docker server 地址，默认为本地的 /var/run/docker.sock
--image-repo string        chaosblade-tool 镜像仓库地址，默认是从 `registry.cn-hangzhou.aliyuncs.com/chaosblade`
```

## 案例

对 nginx 容器 80 端口做访问延迟 3 秒，执行命令如下：

```
blade create docker network delay --time 3000 --interface eth0 --local-port 80 --container-id 5239e26f6329
```

第一次会拉取 chaosblade-tool 镜像，可能会慢一些。返回 `{"code":200,"success":true,"result":"fc3a1b0b4295e47f"}` 表示执行成功，可以看到新启动了一个名字为 5239e26f6329-delay 的容器，通过 sidecar 方式，复用目标容器网络，执行实验。

在本机访问该容器映射出的端口服务，比如映射的端口为 `0.0.0.0:32768->80/tcp`，可以看出发生延迟：

```
[root@izbp11rrxxxx ~]# time curl localhost:32768
real	0m9.001s
user	0m0.004s
sys	0m0.002s
```

此处延迟 9 秒的原因是涉及到多次 80 端口访问。

也可以在同一网段下的另外一台容器内访问目标容器的 80 服务，同样能验证效果：

```
bash-4.4# time curl 172.17.0.2:80
real	0m9.005s
user	0m0.004s
sys	0m0.001s
```

执行以下命令可销毁实验：

```
blade destroy fc3a1b0b4295e47f
```

启动的 sidecar 容器会被销毁，网络恢复。可以通过上述方法再次验证。

```
[root@izbp11rr7oumxxxxx ~]# time curl localhost:32768
real	0m0.011s
user	0m0.003s
sys	0m0.002s
```

## 常见问题

Q：执行命令报错： {"code":604,"success":false,"error":"RTNETLINK answers: File exists\n exit status 2 exit status 1"} A：网络演练场景已存在，可以使用 `docker ps | grep chaosblade` 来查看正在运行的 sidecar 容器


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chaosblade-io.gitbook.io/chaosblade-help-zh-cn/blade-create-docker/blade-create-docker-network.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
