简体   繁体   English

如何不暴露 docker 集群外的端口?

[英]How not to expose port outside docker swarm cluster?

Hello how can I define in compose port only for communication inside cluster?您好,如何在撰写端口中定义仅用于集群内的通信? I don't want to expose my application outside cluster?我不想在集群外公开我的应用程序?

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

Will expose my app outside swarm cluster.将我的应用程序暴露在 swarm 集群之外。 Ho can I make my app accessible only inside cluster via port 80?我可以让我的应用程序只能通过端口 80 在集群内部访问吗?

Just omit the port from the ports section that you do not wish to expose outside the ingress network.只需从ports部分中省略您不希望在入口网络之外公开的端口。 Example nginx.yaml:示例 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

The command will print the response from nginx-2 to nginx-1 accordingly.该命令将相应地打印从 nginx-2 到 nginx-1 的响应。 It is not mandatory to list the port under ports section in order to access a container port within the Swarm network.为了访问 Swarm 网络的容器端口,不必在ports部分列出端口。

For your case it means your sample spec do not need the ports section since you do not wish to expose 80 outside the Swarm network.对于您的情况,这意味着您的示例规范不需要ports部分,因为您不希望将 80 暴露在 Swarm 网络之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该如何在Docker Swarm集群上公开我的API URL? - How should I expose my API URL on a Docker Swarm cluster? 如何通过公共IP将整个docker swarm集群暴露给外部世界? - How to expose the entire docker swarm cluster to the external world via a public IP? Docker AWS 上的 Swarm:公开服务端口在 AWS 虚拟机上不起作用 - Docker Swarm on AWS: Expose service port not working on AWS virtual machine 如何在没有端口映射的情况下将docker容器的ip和端口暴露给外部docker主机? - How to expose docker container's ip and port to outside docker host without port mapping? 如何使用 docker-compose 在 docker/container 之外公开容器端口? - How to expose a container port outside of docker/container using docker-compose? Docker Swarm群集中未打开套接字端口(已识别根本原因) - Socket port not opening in Docker Swarm Cluster (Root Cause Identified) 如何在docker swarm集群中获取服务的Ips? - How to fetch Ips of a service in docker swarm cluster ? 如何在docker swarm上设置zookeeper集群 - How to setup zookeeper cluster on docker swarm 如何在Docker Swarm中设置集群? - How to set up a cluster in Docker Swarm? docker swarm - 如何平衡 swarm 集群中已经运行的容器? - docker swarm - how to balance already running containers in a swarm cluster?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM