0

When using the docker_py library interfacing with a podman daemon, the containers object doesn't seem able to discover containers run by my user, however, are able to discover containers created by the root user.

On my box I have the following:
podman version 4.4.1
py3.9, docker == 6.1.3

for my user I run

podman run --it --rm docker run hello-world

Additionally for my user, at the same time I also run this python snippet.

import docker

self._docker_client: docker.client.DockerClient = docker.from_env()
containers = self._docker_client.containers.list(all=True)
print(f"containers are: {len(containers)}")

The most important thing I notice is that the containers object is empty, even though if I run as my user

podman ps --all

I get results returned.

If I however run the podman run command as the root user, then the python code will return that container.

I'm curious here, is it bad practice to run the docker python library against the podman daemon? I would have thought in the above case that this would have "just worked", however maybe there is something I'm missing here with the namespaces that podman uses?

  • How are you pointing the docker client at your podman user socket? You're creating a client via `docker.from_env()`, so are you setting `DOCKER_HOST` or configuring a docker client context? I wouldn't expect your code to work for either root or rootless podman. – larsks Jul 29 '23 at 03:15
  • @larsks `docker.from_env()` falls back to using `unix:/var/run/docker.sock` which symlinks to `/run/podman/podman.sock` owned by root. Haven't completely confirmed this yet but expect that podman cli run is using the ```/run/user//podman.sock```. If I use `podman --url unix:/var/run/docker run ..` then I now see the containers running in python code. However using `docker.client.DockerClient( base_url="unix:/run/user/30770/podman/podman.sock" )` I get some issues with "Unable to locate server named", continuing investigating. Thanks for the help! – Iamterribleatcoding Jul 29 '23 at 08:32
  • That url is incorrect; you would want `unix:///run/user/30770/podman/podman.sock` (and `unix:///var/run/docker.sock` or `unix:///run/podman/podman.sock` for the system socket). – larsks Jul 29 '23 at 12:13

0 Answers0