docker / docker/docker-py

Trouble publishing same port, two protocols using endpoint_spec

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

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

I'm working on a project where services will need both tcp and udp protocols published for the same ports. When I tried using types.EndpointSpec, the service would start, but with only one wrong port published:

"""
Note: I'm specifying `mode` here for verbosity . This service will only ever have a single 
replica, so leaving it to its default would be equally valid.
"""
ep_spec = EndpointSpec(mode='vip', ports=[
        {27015: (27015, 'tcp', 'host')},
        {27015: (27015, 'udp', 'host')}
    ])

client.services.create(image=server_image,
                       args=svc_args,
                       name=img_name,
                       networks=['dgsm_default'],
                       endpoint_spec=ep_spec)

docker service ls:
image

docker container ls:
image

If I only do a single port, I get similar results:

ep_spec = EndpointSpec(mode='vip', ports=[
        {27015: (27015, 'tcp', 'host')}
    ])

docker service ls:
image

docker container ls:
image

Setting ports to just a dict results in no published ports on the service, but the correct port on the container:

ep_spec = EndpointSpec(mode='vip', ports={27015: (27015, 'tcp', 'host')})

docker service ls:
image

docker container ls:
image

However, I found this comment on #1233 which led me to try this:

ep_spec = {'Ports': [
        {'Protocol': 'tcp', 'PublishedPort': 27015, 'TargetPort': 27015, 'PublishMode': 'host'},
        {'Protocol': 'udp', 'PublishedPort': 27015, 'TargetPort': 27015, 'PublishMode': 'host'}
    ]}

and both protocols show up for the port on the container, (not the service, but this service is reachable from outside the host now):

docker service ls:
image

docker container ls:
image

Am I reading this incorrectly?

Environment details:

(venv) [connor@bigdell dgsm]$ python -V
Python 3.8.0
(venv) [connor@bigdell dgsm]$ pip freeze | grep docker
docker==4.1.0
(venv) [connor@bigdell dgsm]$ docker --version
Docker version 19.03.2, build 6a30dfc
(venv) [connor@bigdell dgsm]$ cat /etc/*-release
CentOS Linux release 7.7.1908 (Core)

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 with the EndpointSpec examples and the ServiceCollection.create documentation, then compare their generated service and container port specifications with the raw Ports dictionary example. Confirm whether both TCP and UDP mappings are represented on the service, and document or test the behavior using the reported Docker 4.1.0 and Engine 19.03.2 environment.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
api, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.