36 lines
711 B
Markdown
36 lines
711 B
Markdown
|
# 使用 docker Gateway
|
||
|
|
||
|
## docker 网络配置
|
||
|
|
||
|
> 一个 docker 网段的创建关联一组 veth 配置,多个需要互相访问的服务尽量在同一网段下使用 docker network 通信,可以解决大多数由网络造成的访问问题。
|
||
|
|
||
|
1. 创建本地网段
|
||
|
|
||
|
```shell
|
||
|
docker network create --ipv6 --subnet=2001:db8:abcd::/64 --gateway=2001:db8:abcd::1 --attachable local
|
||
|
```
|
||
|
|
||
|
2. 容器加入本地网段
|
||
|
```yaml
|
||
|
# docker-compose.yaml
|
||
|
networks:
|
||
|
local:
|
||
|
name: local
|
||
|
external: true
|
||
|
|
||
|
services:
|
||
|
ngx:
|
||
|
container_name: ngx
|
||
|
image: nginx:latest
|
||
|
restart: always
|
||
|
ports:
|
||
|
- 80:80
|
||
|
- 443:443
|
||
|
networks:
|
||
|
- local
|
||
|
|
||
|
# cmd
|
||
|
docker run --networks=local nginx:latest
|
||
|
```
|
||
|
|