方法一

不使用ingress网络,使用host发布服务,只能指定到每一台机
https://github.com/moby/moby/issues/25526

https://xinlc.gitee.io/back-end/docker/docker-swarm-real-client-ip/

#创建host可用网络
docker network create --attachable --driver overlay --subnet 10.13.0.1/16 net00

#方法
docker service create --name my_web \
                        --replicas 3 \
                        --publish published=8080,target=80 \
                        nginx

英文搜索

Unable to retrieve user’s IP address in docker swarm mode



  • docker-compose.yml
services:
  nginx:
    ports:
      - target: 80
        published: 80
        protocol: tcp
        mode: host
      - target: 443
        published: 443
        protocol: tcp
        mode: host