| 用途 | 注入 /etc/hosts 条目 |
|---|---|
| 语法 | --add-host 名称:IP(可多次) |
| 特殊值 | host-gateway 表示宿主机 |
示例
示例
docker run -d --add-host api.internal:10.0.0.8 --add-host host.docker.internal:host-gateway nginx
docker exec <容器> cat /etc/hostsLinux 上 host-gateway 常配合 --add-host host.docker.internal:host-gateway 访问宿主机服务,避免写死 IP。