您好,我如何在組合埠中定義僅用于集群內部的通信?我不想在集群外公開我的應用程式?
version: "3.8"
services:
management:
image: ${IMAGE}
env_file:
- vars.env
networks:
- my-network
ports:
- 8080:80
deploy:
placement:
constraints: [node.role == manager]
replicas: 1
update_config:
parallelism: 2
restart_policy:
condition: on-failure
networks:
my-network:
external: true
ports:
- 8080:80
將在 swarm 集群之外公開我的應用程式。我可以通過埠 80 使我的應用程式只能在集群內部訪問嗎?
uj5u.com熱心網友回復:
只需從ports您不希望在入口網路外部公開的部分中省略埠。nginx.yaml 示例:
version: "3.9"
services:
nginx-1:
image: nginx:alpine
nginx-2:
image: nginx:alpine
docker stack deploy -c nginx.yaml nginx
docker stack ps nginx
docker exec -t <nginx-1 container ID> wget -qO- nginx-2
該命令將相應地列印從 nginx-2 到 nginx-1 的回應。ports為了訪問Swarm 網路中的容器埠,在部分下列出埠不是強制性的。
對于您的情況,這意味著您的示例規范不需要該ports部分,因為您不希望在 Swarm 網路之外公開 80。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/374765.html
