8000 [BUG] docker engine and desktop expose random ports differently · Issue #12846 · docker/compose · GitHub
[go: up one dir, main page]

Skip to content

[BUG] docker engine and desktop expose random ports differently #12846

@alexanderankin

Description

@alexanderankin

Description

exposing ports with a random mapping should be able to be described using docker compose language portably across docker engine and docker desktop environments. however, different options need to be supplied in order to achieve the goal.

services:
  alpine:
    image: nginx:alpine-slim
    init: true
    ports:
      - '81'
      - '82'
      - target: 80
        host_ip: 127.0.0.1
        protocol: tcp
    command:
      - sh
      - -c
      - 'd=/etc/nginx/conf.d; echo "server { listen 81; location / { return 202; } }" > $$d/81.conf && echo "server { listen 82; location / { return 204; } }" > $$d/82.conf && nginx -g "daemon off;"'

  alpine2:
    image: nginx:alpine-slim
    init: true
    ports:
      - target: 80
        host_ip: 127.0.0.1
        protocol: tcp
    command:
      - sh
      - -c
      - 'd=/etc/nginx/conf.d; echo "server { listen 81; location / { return 202; } }" > $$d/81.conf && echo "server { listen 82; location / { return 204; } }" > $$d/82.conf && nginx -g "daemon off;"'

e.g. this works on mac but on linux i also have to add (next to both host_ip fields) a published field and give it a range.

Steps To Reproduce

  1. copy this compose.yaml file onto two computers, one linux (ubuntu 24/Docker version 28.0.4, build b8034c0), one mac (Docker version 27.5.1, build 9f9e405)
  2. cd into the respective directories and docker compose up -d in both
  3. observe linux not works (until adding published)
  4. observe mac works

Compose Version

Docker Compose version v2.32.4-desktop.1
Docker Compose version v2.34.0

Docker Environment

$ docker info | tr '\n' '|' && echo
Client: Docker Engine - Community| Version:    28.0.4| Context:    default| Debug Mode: false| Plugins:|  buildx: Docker Buildx (Docker Inc.)|    Version:  v0.22.0|    Path:     /usr/libexec/docker/cli-plugins/docker-buildx|  compose: Docker Compose (Docker Inc.)|    Version:  v2.34.0|    Path:     /usr/libexec/docker/cli-plugins/docker-compose||Server:| Containers: 2|  Running: 0|  Paused: 0|  Stopped: 2| Images: 10| Server Version: 28.0.4| 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: inactive| Runtimes: io.containerd.runc.v2 runc| Default Runtime: runc| Init Binary: docker-init| containerd version: 753481ec61c7c8955a23d6ff7bc8e4daed455734| runc version: v1.2.5-0-g59923ef| init version: de40ad0| Security Options:|  apparmor|  seccomp|   Profile: builtin|  cgroupns| Kernel Version: 6.8.0-59-generic| Operating System: Ubuntu 24.04.2 LTS| OSType: linux| Architecture: x86_64| CPUs: 16| Total Memory: 27.33GiB| Name: mc-nuc-1| ID: 66bd24bd-1a62-420e-b7c9-05e7bca3d18e| Docker Root Dir: /var/lib/docker| Debug Mode: false| Experimental: false| Insecure Registries:|  ::1/128|  127.0.0.0/8| Live Restore Enabled: false||
$ docker info | tr '\n' '|' && echo
WARNING: daemon is not using the default seccomp profile
Client:| Version:    27.5.1| Context:    desktop-linux| Debug Mode: false| Plugins:|  ai: Ask Gordon - Docker Agent (Docker Inc.)|    Version:  v0.7.3|    Path:     /Users/toor/.docker/cli-plugins/docker-ai|  buildx: Docker Buildx (Docker Inc.)|    Version:  v0.20.1-desktop.2|    Path:     /Users/toor/.docker/cli-plugins/docker-buildx|  compose: Docker Compose (Docker Inc.)|    Version:  v2.32.4-desktop.1|    Path:     /Users/toor/.docker/cli-plugins/docker-compose|  debug: Get a shell into any image or container (Docker Inc.)|    Version:  0.0.38|    Path:     /Users/toor/.docker/cli-plugins/docker-debug|  desktop: Docker Desktop commands (Beta) (Docker Inc.)|    Version:  v0.1.4|    Path:     /Users/toor/.docker/cli-plugins/docker-desktop|  dev: Docker Dev Environments (Docker Inc.)|    Version:  v0.1.2|    Path:     /Users/toor/.docker/cli-plugins/docker-dev|  extension: Manages Docker extensions (Docker Inc.)|    Version:  v0.2.27|    Path:     /Users/toor/.docker/cli-plugins/docker-extension|  feedback: Provide feedback, right in your terminal! (Docker Inc.)|    Version:  v1.0.5|    Path:     /Users/toor/.docker/cli-plugins/docker-feedback|  init: Creates Docker-related starter files for your project (Docker Inc.)|    Version:  v1.4.0|    Path:     /Users/toor/.docker/cli-plugins/docker-init|  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)|    Version:  0.6.0|    Path:     /Users/toor/.docker/cli-plugins/docker-sbom|  scout: Docker Scout (Docker Inc.)|    Version:  v1.16.1|    Path:     /Users/toor/.docker/cli-plugins/docker-scout||Server:| Containers: 9|  Running: 2|  Paused: 0|  Stopped: 7| Images: 31| Server Version: 27.5.1| 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: cgroupfs| Cgroup Version: 2| Plugins:|  Volume: local|  Network: bridge host ipvlan macvlan null overlay|  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog| CDI spec directories:|  /etc/cdi|  /var/run/cdi| Swarm: inactive| Runtimes: io.containerd.runc.v2 runc| Default Runtime: runc| Init Binary: docker-init| containerd version: bcc810d6b9066471b0b6fa75f557a15a1cbf31bb| runc version: v1.1.12-0-g51d5e946| init version: de40ad0| Security Options:|  seccomp|   Profile: unconfined|  cgroupns| Kernel Version: 6.12.5-linuxkit| Operating System: Docker Desktop| OSType: linux| Architecture: aarch64| CPUs: 2| Total Memory: 3.828GiB| Name: docker-desktop| ID: 197e6f69-ae34-44ec-85b6-fc01767f361b| Docker Root Dir: /var/lib/docker| Debug Mode: false| HTTP Proxy: http.docker.internal:3128| HTTPS Proxy: http.docker.internal:3128| No Proxy: hubproxy.docker.internal| Labels:|  com.docker.desktop.address=unix:///Users/toor/Library/Containers/com.docker.docker/Data/docker-cli.sock| Experimental: false| Insecure Registries:|  hubproxy.docker.internal:5555|  127.0.0.0/8| Live Restore Enabled: false||

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0