docker / docker/cli

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

Open
#2,407 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/stack kind/bug
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

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: https://github.com/docker/cli/blob/22acbbcc4b3fb5020492b1ed9e72186191bfedc0/cli/compose/loader/merge.go#L114

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cli/compose/loader/merge.go around line 114 and inspect how ports are keyed while compose files are merged. Reproduce the issue with the provided docker stack deploy example, then verify that the resulting stack publishes both 53/tcp and 53/udp.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.