docker / docker/cli

mapping a container port to multiple host ports doesn't work in host mode

Open
#5,020 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug status/0-triage
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Description

It seems it's not possible to map a single container port to multiple host ports when using host mode. It might be similar to this issue: https://github.com/docker/compose-cli/issues/1655

Reproduce
  1. create a compose file foo.yml
version: "3.4"

services:
  nginx:
    image: nginx
    ports:
      - target: 80
        published: 7500
        protocol: tcp
        mode: host
      - target: 80
        published: 7501
        protocol: tcp
        mode: host
      - target: 90
        published: 7502
        protocol: tcp
        mode: host
  1. deploy the services
docker stack deploy -c foo.yml foo
  1. inspect the service
docker ps | grep foo

example output with the 7500 mapping missing

e52e785d43ab   nginx:latest "/docker-entrypoint.…"   3 minutes ago Up 3 minutes 0.0.0.0:7501->80/tcp, :::7501->80/tcp, 0.0.0.0:7502->90/tcp, :::7502->90/tcp   foo_nginx.1.ynapf1jho2sg2jib4391j1tej
Expected behavior

Both ports 7500 and 7501 should have been mapped, but only the last one was.

docker version
Client: Docker Engine - Community
 Version:           26.0.0
 API version:       1.45
 Go version:        go1.21.8
 Git commit:        2ae903e
 Built:             Wed Mar 20 15:18:12 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.0.0
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       8b79278
  Built:            Wed Mar 20 15:18:12 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
docker info
Client: Docker Engine - Community
 Version:    26.0.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.13.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.25.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose
  scan: Docker Scan (Docker Inc.)
    Version:  v0.23.0
    Path:     /usr/libexec/docker/cli-plugins/docker-scan

Server:
 Containers: 97
  Running: 39
  Paused: 0
  Stopped: 58
 Images: 55
 Server Version: 26.0.0
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: active
  NodeID: rnkuw1h18qfave5s02qrpil4g
  Is Manager: true
  ClusterID: ibv4nqt659hdxmqv32gkk7a49
  Managers: 1
  Nodes: 1
  Default Address Pool: 10.0.0.0/8  
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 172.20.3.61
  Manager Addresses:
   172.20.3.61:2377
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.10.0-28-amd64
 Operating System: Debian GNU/Linux 11 (bullseye)
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 15.53GiB
 Name: cldev10
 ID: TRKH:KEBO:ESTR:OKOG:NACA:LTD6:RN34:5TFK:TJCM:WE44:LDXK:A6HY
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  aadocker01.as-i.com:5000
  127.0.0.0/8
 Live Restore Enabled: false
Additional Info

No response

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 by reproducing the issue with the provided foo.yml and docker stack deploy command, then inspect the Docker CLI path handling Swarm service port mappings in host mode. Done means both published ports 7500 and 7501 appear in docker ps while the port 7502 mapping remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.