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

podman ps --format '{{.Label "mylabel"}}' fails with executing "ps" at <.Label>: can't evaluate field Label in type containers.psReporter #20957

Closed
eriksjolund opened this issue Dec 9, 2023 · 0 comments · Fixed by #20958
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.

Comments

@eriksjolund
Copy link
Contributor

Issue Description

$ podman ps --format '{{.Label "mylabel"}}'
Error: template: ps:1:13: executing "ps" at <.Label>: can't evaluate field Label in type containers.psReporter
$

The same command does not fail when trying it out on docker.

Steps to reproduce the issue

Steps to reproduce the issue

  1. sudo useradd test
  2. sudo machinectl shell --uid test
  3. podman run --rm --label mylabel=hello -q -d docker.io/library/alpine sleep inf
  4. podman ps --format '{{.Label "mylabel"}}'

Describe the results you received

The command in step 4 fails and prints the error message

Error: template: ps:1:13: executing "ps" at <.Label>: can't evaluate field Label in type containers.psReporter

Describe the results you expected

I expected the command in step 4 to succeed and print

hello

podman info output

host:
  arch: amd64
  buildahVersion: 1.33.2
  cgroupControllers:
  - cpu
  - io
  - memory
  - pids
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.1.8-2.fc39.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.8, commit: '
  cpuUtilization:
    idlePercent: 99.74
    systemPercent: 0.2
    userPercent: 0.06
  cpus: 16
  databaseBackend: sqlite
  distribution:
    distribution: fedora
    variant: workstation
    version: "39"
  eventLogger: journald
  freeLocks: 2047
  hostname: asus
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 50192
      size: 1
    - container_id: 1
      host_id: 67744801
      size: 1000000
    uidmap:
    - container_id: 0
      host_id: 50192
      size: 1
    - container_id: 1
      host_id: 67813730
      size: 1000000
  kernel: 6.6.4-200.fc39.x86_64
  linkmode: dynamic
  logDriver: journald
  memFree: 5928484864
  memTotal: 7686619136
  networkBackend: netavark
  networkBackendInfo:
    backend: netavark
    dns:
      package: aardvark-dns-1.8.0-1.fc39.x86_64
      path: /usr/libexec/podman/aardvark-dns
      version: aardvark-dns 1.8.0
    package: netavark-1.8.0-2.fc39.x86_64
    path: /usr/libexec/podman/netavark
    version: netavark 1.8.0
  ociRuntime:
    name: crun
    package: crun-1.12-1.fc39.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.12
      commit: ce429cb2e277d001c2179df1ac66a470f00802ae
      rundir: /run/user/50192/crun
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +LIBKRUN +WASM:wasmedge +YAJL
  os: linux
  pasta:
    executable: /usr/bin/pasta
    package: passt-0^20231119.g4f1709d-1.fc39.x86_64
    version: |
      pasta 0^20231119.g4f1709d-1.fc39.x86_64
      Copyright Red Hat
      GNU General Public License, version 2 or later
        <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.
  remoteSocket:
    exists: false
    path: /run/user/50192/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: true
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: true
  serviceIsRemote: false
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.2.2-1.fc39.x86_64
    version: |-
      slirp4netns version 1.2.2
      commit: 0ee2d87523e906518d34a6b423271e4826f71faf
      libslirp: 4.7.0
      SLIRP_CONFIG_VERSION_MAX: 4
      libseccomp: 2.5.3
  swapFree: 7686057984
  swapTotal: 7686057984
  uptime: 0h 38m 50.00s
  variant: ""
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - docker.io
  - quay.io
store:
  configFile: /home/test695/.config/containers/storage.conf
  containerStore:
    number: 1
    paused: 0
    running: 1
    stopped: 0
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /home/test695/.local/share/containers/storage
  graphRootAllocated: 407822663680
  graphRootUsed: 388686446592
  graphStatus:
    Backing Filesystem: xfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Supports shifting: "false"
    Supports volatile: "true"
    Using metacopy: "false"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 2
  runRoot: /run/user/50192/containers
  transientStore: false
  volumePath: /home/test695/.local/share/containers/storage/volumes
version:
  APIVersion: 4.8.1
  Built: 1701777650
  BuiltTime: Tue Dec  5 13:00:50 2023
  GitCommit: ""
  GoVersion: go1.21.4
  Os: linux
  OsArch: linux/amd64
  Version: 4.8.1

Podman in a container

No

Privileged Or Rootless

Rootless

Upstream Latest Release

Yes

Additional environment details

Additional environment details

Additional information

It works when using docker.

$ docker run --rm --label mylabel=hello -q -d docker.io/library/alpine sleep inf
d180a9de004113adfc1c6b72da027ac8416a57d64ac884a6abf8bc61dfb42eba
$ docker ps --format '{{.Label "mylabel"}}'
hello
$ rpm -qf /usr/bin/docker
moby-engine-24.0.5-1.fc39.x86_64

Side note 1:
In a more realistic scenario you would probably like to filter the containers

$ docker ps --filter label=mylabel --format '{{.Label "mylabel"}}'
hello

Side note 2:
I found this issue when looking at the issues in the nerdctl project. I checked if Podman had a similar issue as

After that I found a similar old Podman issue from 2018:

Long time has gone since 2018. Maybe the issue is more relevant now?
Feel free to close this issue if it's of low priority.

@eriksjolund eriksjolund added the kind/bug Categorizes issue or PR as related to a bug. label Dec 9, 2023
rhatdan added a commit to rhatdan/podman that referenced this issue Dec 13, 2023
Also Support for podman pod ps  --format '{{ .Label label }}'

Finally fix support for --format '{{ .Podname }}'
   When user specifies .Podname this implies --pod was passed.

Fixes: containers#20957

Signed-off-by: Daniel J Walsh <[email protected]>
@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 Mar 13, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 2024
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant