Skip to content

docker stack can't publish udp and tcp for the same port #2407

@lneva-fastly

Description

@lneva-fastly

Description

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:

  1. 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.

Output of docker version:

19.03.8 client and server

Additional details:

The problem is in this function:

m[p.Published] = p

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions