Skip to content

[BUG] containers.list() returns a list of containers with partial/missing "Mounts" attribute values #488

@D3vil0p3r

Description

@D3vil0p3r

During my tests I noted that podman py containers.list() function returns a list of containers with partial/missing Mounts attribute values.

In particular, the Mounts attribute values are correctly returned when containers.create() function is used but not when containers.list() is used.

Here the Python code with the evidence (remember to change source values with some your existing dirs`):

import podman
from podman import PodmanClient

client = podman.from_env()
client.ping()
docker_create_function = client.containers.create
docker_args = {"image": "athenaos/base:latest",
               "name": "exegol-default",
               "mounts": [
                    {'target': '/opt/resources', 'source': '/home/athena/Exegol/exegol-resources', 'type': 'bind'},
                    {'target': '/workspaces', 'source': '/home/athena/.exegol/workspaces', 'type': 'bind'}
                ]}

container = docker_create_function(**docker_args)
print(container.attrs.get("Mounts", []))

print("Now use client.containers.list:")
docker_containers = client.containers.list(all=True, filters={"name": "exegol-"})

for container in docker_containers:
    print(container.attrs.get("Mounts", []))

After docker_create_function(**docker_args), the Mounts values are correctly returned as:

[{'Type': 'bind', 'Source': '/home/athena/Exegol/exegol-resources', 'Destination': '/opt/resources', 'Driver': '', 'Mode': '', 'Options': ['rbind'], 'RW': True, 'Propagation': 'rprivate'}, {'Type': 'bind', 'Source': '/home/athena/.exegol/workspaces', 'Destination': '/workspaces', 'Driver': '', 'Mode': '', 'Options': ['rbind'], 'RW': True, 'Propagation': 'rprivate'}]

Instead, when using client.containers.list(all=True), the Mounts values are erroneously returned as:

['/opt/resources', '/workspaces']

so, the other values are missing. Remember to remove the container by podman container stop exegol-default && podman container rm exegol-default to rerun the script above.

Docker py works correctly on both the cases.

Some useful information:

container.list() gets container info by:

response = self.client.get("/containers/json", params=params)

The content of this response is:

[{'AutoRemove': False, 'Command': ['/usr/bin/bash'], 'Created': '2024-12-19T20:39:51.101254185+01:00', 'CreatedAt': '', 'CIDFile': '', 'Exited': False, 'ExitedAt': -62135596800, 'ExitCode': 0, 'ExposedPorts': None, 'Id': '11ee4f548ec98c2be5bd41337a0cef75c3ecf8b7be56304055ad80e60eedd5c3', 'Image': 'docker.io/athenaos/base:latest', 'ImageID': '420f00cb47debe421a8b70b1a2e9ccf16a942cce2f70d1724eff6be764e95fea', 'IsInfra': False, 'Labels': None, 'Mounts': ['/opt/resources', '/workspaces'], 'Names': ['exegol-default'], 'Namespaces': {}, 'Networks': [], 'Pid': 0, 'Pod': '', 'PodName': '', 'Ports': None, 'Restarts': 0, 'Size': None, 'StartedAt': -62135596800, 'State': 'created', 'Status': ''}]

and the problem is that Mounts here has missing information.

I don't understand why this GET request does not take all the info, indeed by using podman cli, I can easily get those missing information:

podman inspect exegol-default --format "{{ .Mounts }}"

[{bind  /home/athena/Exegol/exegol-resources /opt/resources   [rbind] true rprivate } {bind  /home/athena/.exegol/workspaces /workspaces   [rbind] true rprivate }]

Also, by starting the API service by:

podman system service tcp:localhost:8080 --time=0 &

and running:

curl -k http://localhost:8080/v4.0.0/libpod/containers/json?all=true | jq

we get:

...
    "Labels": null,
    "Mounts": [
      "/opt/resources",
      "/workspaces"
    ],
    "Names": [
      "exegol-default"
    ],
...

so, probably the issue is on REST API side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions