Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker ps --fitler 'name=^/...$ (leading slash in container name) does not work with Podman macOS helper #16663

Closed
Frederick888 opened this issue Nov 29, 2022 · 7 comments · Fixed by #16820
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. macos MacOS (OSX) related remote Problem is in podman-remote

Comments

@Frederick888
Copy link

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

Steps to reproduce the issue:

  1. docker run --rm -it --name foo archlinux:latest bash

  2. docker ps --filter 'name=^/foo$

Describe the results you received:

No container listed (despite that docker container inspect foo --format {{.Name}} has a leading slash.)

Describe the results you expected:

Both docker ps --filter 'name=^/foo$ and docker ps --filter 'name=^foo$ work like Docker (confirmed with both macOS Docker Desktop and Docker Linux).

Additional information you deem important (e.g. issue happens only occasionally):

Output of podman version:

Client:       Podman Engine
Version:      4.3.1
API Version:  4.3.1
Go Version:   go1.18.8
Built:        Thu Nov 10 07:43:58 2022
OS/Arch:      darwin/amd64

Server:       Podman Engine
Version:      4.3.0
API Version:  4.3.0
Go Version:   go1.19.2
Built:        Fri Oct 21 19:09:51 2022
OS/Arch:      linux/amd64

(Podman 4.3.1 hasn't hit CoreOS yet.)

Output of podman info:

host:
  arch: amd64
  buildahVersion: 1.28.0
  cgroupControllers:
  - cpuset
  - cpu
  - io
  - memory
  - hugetlb
  - pids
  - misc
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.1.4-3.fc37.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.4, commit: '
  cpuUtilization:
    idlePercent: 61.93
    systemPercent: 28.82
    userPercent: 9.25
  cpus: 6
  distribution:
    distribution: fedora
    variant: coreos
    version: "37"
  eventLogger: journald
  hostname: localhost.localdomain
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 6.0.7-301.fc37.x86_64
  linkmode: dynamic
  logDriver: journald
  memFree: 9939951616
  memTotal: 16771788800
  networkBackend: netavark
  ociRuntime:
    name: crun
    package: crun-1.6-2.fc37.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.6
      commit: 18cf2efbb8feb2b2f20e316520e0fd0b6c41ef4d
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +LIBKRUN +YAJL
  os: linux
  remoteSocket:
    exists: true
    path: /run/podman/podman.sock
  security:
    apparmorEnabled: false
    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: /usr/share/containers/seccomp.json
    selinuxEnabled: true
  serviceIsRemote: true
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.2.0-5.fc37.x86_64
    version: |-
      slirp4netns version 1.2.0
      commit: 656041d45cfca7a4176f6b7eed9e4fe6c11e8383
      libslirp: 4.7.0
      SLIRP_CONFIG_VERSION_MAX: 4
      libseccomp: 2.5.3
  swapFree: 0
  swapTotal: 0
  uptime: 1h 6m 59.00s (Approximately 0.04 days)
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  volume:
  - local
registries:
  search:
  - docker.io
store:
  configFile: /usr/share/containers/storage.conf
  containerStore:
    number: 18
    paused: 0
    running: 17
    stopped: 1
  graphDriverName: overlay
  graphOptions:
    overlay.mountopt: nodev,metacopy=on
  graphRoot: /var/lib/containers/storage
  graphRootAllocated: 106825756672
  graphRootUsed: 47299170304
  graphStatus:
    Backing Filesystem: xfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "true"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 59
  runRoot: /run/containers/storage
  volumePath: /var/lib/containers/storage/volumes
version:
  APIVersion: 4.3.0
  Built: 1666339791
  BuiltTime: Fri Oct 21 19:09:51 2022
  GitCommit: ""
  GoVersion: go1.19.2
  Os: linux
  OsArch: linux/amd64
  Version: 4.3.0

Package info (e.g. output of rpm -q podman or apt list podman or brew info podman):

# in VM
$ rpm -q podman
podman-4.3.0-2.fc37.x86_64

# in macOS
$ brew info podman
brew info podman
==> podman: stable 4.3.1 (bottled), HEAD
Tool for managing OCI containers and pods
https://podman.io/
/usr/local/Cellar/podman/4.3.1 (185 files, 48MB) *
  Poured from bottle on 2022-11-24 at 16:22:12
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/podman.rb
License: Apache-2.0 and GPL-3.0-or-later
==> Dependencies
Build: go-md2man ✘, [email protected] ✘
Required: qemu ✔
==> Options
--HEAD
        Install HEAD version
==> Caveats
zsh completions have been installed to:
  /usr/local/share/zsh/site-functions

To restart podman after an upgrade:
  brew services restart podman
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/podman/bin/podman system service --time=0
==> Analytics
install: 29,640 (30 days), 79,815 (90 days), 238,131 (365 days)
install-on-request: 27,177 (30 days), 75,512 (90 days), 232,844 (365 days)
build-error: 24 (30 days)

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide?

Yes

Additional environment details (AWS, VirtualBox, physical, etc.):

# in macOS
$ docker --version
Docker version 20.10.21, build baeda1f
@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Nov 29, 2022
@github-actions github-actions bot added macos MacOS (OSX) related remote Problem is in podman-remote labels Nov 29, 2022
@vrothberg
Copy link
Member

Thanks for reaching out, @Frederick888!

I can reproduce with the "local" binary on Linux as well. Do you know what this slash is intended for? It doesn't look like a regular expression to me.

@rhatdan
Copy link
Member

rhatdan commented Dec 12, 2022

I think the want to have a container named /foo So it is not part of the regular expression.

@mheon
Copy link
Member

mheon commented Dec 12, 2022 via email

@rhatdan
Copy link
Member

rhatdan commented Dec 12, 2022

Looks like it is legal with Docker.

# docker run --rm --name /foo alpine echo hi
hi

@rhatdan
Copy link
Member

rhatdan commented Dec 12, 2022

Docker seems to allow the names to start with "/"

func (daemon *Daemon) reserveName(id, name string) (string, error) {
	if !validContainerNamePattern.MatchString(strings.TrimPrefix(name, "/")) {
		return "", errdefs.InvalidParameter(errors.Errorf("Invalid container name (%s), only %s are allowed", name, validContainerNameChars))
	}
	if name[0] != '/' {
		name = "/" + name
	}

@Frederick888
Copy link
Author

Thanks for reaching out, @Frederick888!

I can reproduce with the "local" binary on Linux as well. Do you know what this slash is intended for? It doesn't look like a regular expression to me.

Looks like this was introduced in moby/moby#2162 (moby/moby@256b753 to be specific). After skimming through the PR, I guess it represents some sort of namespace, and a leading / perhaps means the root namespace.

And not only does it allow container names to have a leading slash, it also makes sure --filter <regex> is matched against both the 'full name' with slash and the one without. For example, using Docker Linux,

# start a container without a leading slash in name explicitly
$ docker run --rm -it --name arch archlinux bash

# I can use a regex with the slash
$ docker ps --filter 'name=^/arch$'
CONTAINER ID   IMAGE       COMMAND   CREATED          STATUS          PORTS     NAMES
713399f8ab17   archlinux   "bash"    30 seconds ago   Up 29 seconds             arch

# or without
$ docker ps --filter 'name=^arch$'
CONTAINER ID   IMAGE       COMMAND   CREATED          STATUS          PORTS     NAMES
713399f8ab17   archlinux   "bash"    48 seconds ago   Up 47 seconds             arch

# same results if I use --name /arch to start the container

The name from docker container inspect always has a leading slash though, and interestingly Docker CLI + Podman socket under macOS adds the slash too:

# Docker Linux
$ docker container inspect arch --format {{.Name}}
/arch

# Docker CLI macOS + Podman
$ podman run --rm -it --name arch archlinux bash
$ docker container inspect arch --format {{.Name}}
/arch
$ podman container inspect arch --format {{.Name}}
arch

@Frederick888
Copy link
Author

And as expected:

# Docker Linux
$ docker run --rm -it --name /arch archlinux bash
$ docker run --rm -it --name arch archlinux bash
docker: Error response from daemon: Conflict. The container name "/arch" is already in use by container "436c07d4a7af53d899228d5f2831b9ec0881f211c3ebc7a72ac855db7bb3f50d". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.

rhatdan added a commit to rhatdan/podman that referenced this issue Dec 26, 2022
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. macos MacOS (OSX) related remote Problem is in podman-remote
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants