如何檢查我的 extra_hosts 配置是否有效?
version: '3.5'
services:
nginx:
image: nginx:stable
extra_hosts:
- "host.docker.internal:host-gateway"
我試過 docker exec nginx /bin/sh -c 'ping host.docker.internal'
但得到 /bin/sh: 1: ping: not found
nginx docker 映像中是否有某種 ping 替代方法可用?
在 Ubuntu 20.04.3 LTS 主機上進行測驗,使用 docker 版本 20.10.11 和 docker-compose 版本 1.29.2。
uj5u.com熱心網友回復:
nginx鏡像沒有自帶ping命令,可以加一個busybox測驗進出:
cat << EOF > docker-compose.yaml
version: '3.5'
services:
nginx:
image: nginx:stable
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- 8080:80
busybox:
image: busybox
extra_hosts:
- "host.docker.internal:host-gateway"
command: ash -c 'sleep 3600'
EOF
docker-compose up -d
docker-compose exec busybox ping host.docker.internal
docker-compose exec busybox wget -qO- nginx
docker-compose exec busybox wget -qO- host.docker.internal:8080
docker-compose down
uj5u.com熱心網友回復:
始終使用sidecar容器,不要壓倒主影像:
k8s 社區為網路除錯提供了良好的形象,其中包括幾乎所有著名的 CLI:dig、nslookup、ping 等
k8s.gcr.io/e2e-test-images/jessie-dnsutils:1.3
以與gohm'c解釋的 busybox 方式相同的方式使用它
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/378593.html
