containers / podman

Podman: A tool for managing OCI containers and pods.
https://podman.io
Apache License 2.0
22.4k stars 2.31k forks source link

Container create does not allow host port ranges #22980

Closed DominicLavery closed 3 weeks ago

DominicLavery commented 3 weeks ago

Issue Description

When creating a container via dockers api, you can provide a range of ports for the host port. Docker will bind a port from this range that has not already been allocated. The range is specified with a dash e.g. 8080-8090

Calling the podman API with a range in this way results in an error.

The same can be seen calling the create subcommands. e.g. docker create -p 8080-8090:80 alpine sleep 100

Steps to reproduce the issue

Steps to reproduce the issue

  1. Run docker create -p 8080-8090:80 alpine sleep 100 on a system with docker installed and see it is accepted. The container can then be started
  2. Run docker create -p 8080-8090:80 alpine sleep 100 on a system with podman installed and see the error

Describe the results you received

Error response from daemon: make cli opts(): strconv.Atoi: parsing "8080-8090": invalid syntax

Which appears to originate from: https://github.com/containers/podman/blob/bd00c6fef9b8dce1784fd531a8f3037eafb69008/pkg/api/handlers/compat/containers_create.go#L263

Describe the results you expected

No error returned and the container created with a port from the provided range allocated

podman info output

host:
  arch: amd64
  buildahVersion: 1.35.3
  cgroupControllers:
  - cpuset
  - cpu
  - io
  - memory
  - hugetlb
  - pids
  - rdma
  - misc
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon_2.0.25+ds1-1.1_amd64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.25, commit: unknown'
  cpuUtilization:
    idlePercent: 85.52
    systemPercent: 1.73
    userPercent: 12.76
  cpus: 4
  databaseBackend: sqlite
  distribution:
    codename: jammy
    distribution: ubuntu
    version: "22.04"
  eventLogger: journald
  freeLocks: 2039
  hostname: ip-10-0-125-240
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 6.5.0-1020-aws
  linkmode: dynamic
  logDriver: journald
  memFree: 6655250432
  memTotal: 16459624448
  networkBackend: netavark
  networkBackendInfo:
    backend: netavark
    dns:
      package: Unknown
      path: /usr/lib/podman/aardvark-dns
      version: aardvark-dns 1.6.0
    package: Unknown
    path: /usr/lib/podman/netavark
    version: netavark 1.4.0
  ociRuntime:
    name: runc
    package: runc_1.1.7-0ubuntu1~22.04.2_amd64
    path: /usr/sbin/runc
    version: |-
      runc version 1.1.7-0ubuntu1~22.04.2
      spec: 1.0.2-dev
      go: go1.18.1
      libseccomp: 2.5.3
  os: linux
  pasta:
    executable: ""
    package: ""
    version: ""
  remoteSocket:
    exists: true
    path: /run/podman/podman.sock
  security:
    apparmorEnabled: true
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: false
    seccompEnabled: true
    seccompProfilePath: ""
    selinuxEnabled: false
  serviceIsRemote: false
  slirp4netns:
    executable: ""
    package: ""
    version: ""
  swapFree: 0
  swapTotal: 0
  uptime: 0h 36m 23.00s
  variant: ""
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries:
  search:
  - docker.io
store:
  configFile: /usr/share/containers/storage.conf
  containerStore:
    number: 7
    paused: 0
    running: 4
    stopped: 3
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /var/lib/containers/storage
  graphRootAllocated: 155897610240
  graphRootUsed: 16994643968
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Supports shifting: "true"
    Supports volatile: "true"
    Using metacopy: "false"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 9
  runRoot: /run/containers/storage
  transientStore: false
  volumePath: /var/lib/containers/storage/volumes
version:
  APIVersion: 5.0.2
  Built: 1718185918
  BuiltTime: Wed Jun 12 09:51:58 2024
  GitCommit: 3304dd95b8978a8346b96b7d43134990609b3b29
  GoVersion: go1.22.2
  Os: linux
  OsArch: linux/amd64
  Version: 5.0.2

Podman in a container

No

Privileged Or Rootless

Privileged

Upstream Latest Release

Yes

Additional environment details

I've tested this in podman 5.0.2 on linux on an EC2 instance I've also attempted it on podman desktop on mac against 5.1.1

Additional information

I have time to contribute a PR for this issue. Any advice about how best to solve this would be appreciated

Luap99 commented 3 weeks ago

Duplicate of #15111

This isn't a simple parsing fix as libpod internally has no way to represent such range.