I have both compose & stack files with nginx service as
networks:
custom_overlay_network:
external: true
services:
proxy:
image: nginx:alpine
ports:
- target: 80
published: 80
protocol: tcp
mode: host
networks:
- custom_overlay_network
I also have tried a short ports variant:
ports:
- "80:80"
here are networks settings nginx service in swarm (with/without mode: host
)
"NetworkSettings": {
"Bridge": "",
"SandboxID": "c8d0dbff010c840f79d3e6c7ab7c0a225312ae6e28945e310a5f433f23baaadb",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": null
},
"SandboxKey": "/var/run/docker/netns/c8d0dbff010c",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
...
and here are setting nginx service in compose mode
"NetworkSettings": {
"Bridge": "",
"SandboxID": "22510ac75ac8e48f2c555d2bfc71ab47928ece59445b0db593eab882e26251e2",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
}
]
},
"SandboxKey": "/var/run/docker/netns/22510ac75ac8",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
when I run the service as compose - I have access to http://localhost
content
but if I run service in swarm mode - I have no access to http://localhost
I also have no access to http://<network IP address>
try something like this
version: '3.7'
networks:
custom_overlay_network:
services:
nginx:
image: nginx:alpine
hostname: nginx
restart: always
ports:
- 80:80
networks:
- custom_overlay_network