You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
docker stack can't publish udp and tcp for the same port #2407
Using docker stack deploy, it is not possible to publish the same port as both UDP and TCP. An example where this is important is DNS.
Steps to reproduce the issue:
Deploy the following stack:
version: '3.7'
services:
consul:
image: consul
command: agent -dev
ports:
# Port 8600 is the consul DNS query interface.
# Mapping this to port 53 allows us to use this as our nameserver.
- target: 8600
published: 53
protocol: tcp
- target: 8600
published: 53
protocol: udp
networks:
- consul
networks:
consul:
Describe the results you received:
Only the second port (53/udp) is published.
Describe the results you expected:
Both ports are published.
Additional information you deem important (e.g. issue happens only occasionally):
This may only occur if you specify multiple docker-compose yaml files that are merged by docker stack deploy. I haven't tested with just a single compose file.
When merging, ports are placed into a map keyed on the port number. If the same port is published twice (udp and tcp), the second protocol wins because it overwrites the first. This map should instead be keyed on (port, protocol).
I have the exact same issue, and came to the same conclusion.
This may only occur if you specify multiple docker-compose yaml files that are merged by docker stack deploy. I haven't tested with just a single compose file.
This doesn't occur with a single compose file.
It's possible to reproduce the issue with docker stack config only, without deploying with docker stack deploy:
Activity
lneva-fastly commentedon Mar 27, 2020
As a note, this problem does not occur if you run
docker service createmanually.ngrilly commentedon Apr 11, 2024
I have the exact same issue, and came to the same conclusion.
This doesn't occur with a single compose file.
It's possible to reproduce the issue with
docker stack configonly, without deploying withdocker stack deploy:One temporary workaround is put the compose file with the ports at the end:
The solution would be to fix toServicePortConfigsMap in github.com/docker/cli/cli/compose/loader/merge.go by using a composite key (published port + protocol, instead of published port only), like in github.com/moby/swarmkit/manager/scheduler.HostPortFilter.Check.
PawsFunctions commentedon Nov 18, 2026
+1 on version