解决办法

修改ports
例如如下服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
nginx:
image: "nginx:alpine"
ports:
- target: 80
published: 80
protocol: tcp
mode: host
- target: 443
published: 443
protocol: tcp
mode: host
networks:
backend:
aliases:
- "nginx"

其他介绍
原文地址
https://blog.csdn.net/fengyilin_henu/article/details/84912763

host模式和ingress模式介绍
http://c.biancheng.net/view/3195.html

正常发布服务后,使用host模式更新服务

1
2
3
4
5
docker service update app_nginx \
--publish-rm 80 \
--publish-add "mode=host,published=80,target=80" \
--publish-rm 443 \
--publish-add "mode=host,published=443,target=443"

用了mode=host应用就不会利用ingress网络,所以服务对应的task在哪个节点上那个节点才能接收外部请求,为了还要满足在任意节点上都可以访问到服务,所以把发布模式定义成了global