1 回答

TA貢獻1786條經驗 獲得超11個贊
看到這個人為的例子:
version: "3"
services:
server:
image: nginx:1.17.3
restart: always
container_name: nginx
expose:
- "80"
ports:
- 8888:80
client:
image: busybox:1.31.0
restart: always
depends_on:
- server
container_name: busybox
command:
- ash
- -c
- |
while true;
do
wget --spider http://server:80 2>&1
sleep 5s;
done;
client通過端口訪問 Nginx 容器80,但它用作server主機地址以解析到適當的 (Nginx) 容器。
如果您要替換server為localhostin client,則客戶端會嘗試wget對自己執(zhí)行命令,但會失敗。
因為server發(fā)布8888到主機,當 Docker Compose 啟動時,從主機(?。憧梢詗get http://localhost:8888并且這將起作用(200)。
添加回答
舉報