Skip to content

Commit

Permalink
doc: update docs/docker.md #583
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 29, 2024
1 parent ce2640f commit 37906f6
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ Docker 备忘清单
----
<!--rehype:body-class=cols-2-->

### 安装
### 入门

#### 安装

```shell
curl -sSL https://get.docker.com/ | sh
sudo chmod 777 /var/run/docker.sock
```

### 入门
<!--rehype:wrap-class=row-span-2-->

在后台创建和运行容器

```shell
Expand Down Expand Up @@ -177,66 +176,72 @@ Docker 网络
----
<!--rehype:body-class=cols-2-->

### 操作

获取容器连接的网络
### 创建网络

```shell
docker inspect MyContainer | grep Network
docker network create -d overlay MyOverlayNetwork
docker network create -d bridge MyBridgeNetwork
```

删除网络
自定义网络子网和网关

```shell
docker network rm MyOverlayNetwork
docker network create -d overlay \
--subnet=192.168.0.0/16 \
--subnet=192.170.0.0/16 \
--gateway=192.168.0.100 \
--gateway=192.170.0.100 \
--ip-range=192.168.1.0/24 \
--aux-address="my-router=192.168.1.5" \
--aux-address="my-switch=192.168.1.6" \
--aux-address="my-printer=192.170.1.5" \
--aux-address="my-nas=192.170.1.6" \
MyOverlayNetwork
```

列出网络
### 操作
<!--rehype:wrap-class=row-span-3-->

获取容器连接的网络

```shell
docker network ls
docker inspect MyContainer | grep Network
```

获取有关网络的信息

```shell
docker network inspect MyOverlayNetwork
docker network inspect <network_name>
```

将正在运行的容器连接到网络

```shell
docker network connect MyOverlayNetwork nginx
docker network connect <network_name> <container_name>
```

启动时将容器连接到网络

```shell
docker run -it -d --network=MyOverlayNetwork nginx
docker run -it -d --network=<network_name> <container_name>
```

断开容器与网络的连接

```shell
docker network disconnect MyOverlayNetwork nginx
docker network disconnect <network_name> <container_name>
```

### 创建网络
### 删除网络

```bash
docker network rm <network_name>
```

### 列出网络

```shell
docker network create -d overlay MyOverlayNetwork
docker network create -d bridge MyBridgeNetwork
docker network create -d overlay \
--subnet=192.168.0.0/16 \
--subnet=192.170.0.0/16 \
--gateway=192.168.0.100 \
--gateway=192.170.0.100 \
--ip-range=192.168.1.0/24 \
--aux-address="my-router=192.168.1.5" \
--aux-address="my-switch=192.168.1.6" \
--aux-address="my-printer=192.170.1.5" \
--aux-address="my-nas=192.170.1.6" \
MyOverlayNetwork
docker network ls
```

Docker 快捷键
Expand Down

0 comments on commit 37906f6

Please sign in to comment.