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 run not working #201

Closed
KaiBroeker opened this issue Aug 25, 2022 · 5 comments · Fixed by #226
Closed

podman run not working #201

KaiBroeker opened this issue Aug 25, 2022 · 5 comments · Fixed by #226
Assignees

Comments

@KaiBroeker
Copy link

Hello,

I use the lib version 4.2.0, Python 3.10.4, podman 3.4.4.

If I try to use client.containers.run I get the following error:

>>> import podman
>>> 
>>> client = podman.PodmanClient()
>>> 
>>> client.images.pull("docker.io/library/ubuntu:20.04")
<Image: 'docker.io/library/ubuntu:20.04'>
>>> 
>>> image = client.images.pull("docker.io/library/ubuntu:20.04")
>>> 
>>> client.containers.run(image, ["ls", "/"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kai/.local/lib/python3.10/site-packages/podman/domain/containers_run.py", line 80, in run
    exit_status = container.wait()["StatusCode"]
TypeError: 'int' object is not subscriptable
>>> 

Are I'm doing something wrong or is there a bug?

Thanks for the help
Kai

@ericpershey
Copy link
Contributor

Same thing with lib version 4.2.0, Python 3.9.7, podman 4.2.0. I tried debugging this for a few hours and found that container.wait() is returning from requests and is valid json, which is a single integer. That line attempts to then treat it as a dictionary and pull the key StatusCode out, which fails in a TypeError. I was never able to get past this either.

>>> import json; json.loads(json.dumps(0))
0
>>>podman --version
podman version 4.2.0

>>>python -c "import podman; print(podman.__version__)"
4.2.0

import podman
uri = "http://127.0.0.1:8090"
client = podman.PodmanClient(base_url=uri)
client.images.pull("docker.io/library/ubuntu:20.04")
image = client.images.pull("docker.io/library/ubuntu:20.04")
client.containers.run(image, ["ls", "/"])        

>>>python
Python 3.9.7 (default, Sep 16 2021, 13:09:58)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import podman
>>> uri = "http://127.0.0.1:8090"
>>> client = podman.PodmanClient(base_url=uri)
>>> client.images.pull("docker.io/library/ubuntu:20.04")
<Image: 'docker.io/library/ubuntu:20.04'>
>>> image = client.images.pull("docker.io/library/ubuntu:20.04")
>>> client.containers.run(image, ["ls", "/"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "****/lib/python3.9/site-packages/podman/domain/containers_run.py", line 80, in run
    exit_status = container.wait()["StatusCode"]
TypeError: 'int' object is not subscriptable
>>>
        

@rhatdan
Copy link
Member

rhatdan commented Aug 31, 2022

@cdoern @mwhahaha PTAL

@cdoern
Copy link
Collaborator

cdoern commented Sep 5, 2022

this is not new for 4.2 or the previous version, unless something changes with the container wait method in podman. I will look at this.

@cdoern cdoern self-assigned this Sep 5, 2022
@ericpershey
Copy link
Contributor

It seems the wait on libpod returns a single integer rather than json with StatusCode. This may be all because I am using http://127.0.0.1:8090.
https://docs.podman.io/en/latest/_static/api.html#tag/containers/operation/ContainerWaitLibpod
vs
https://docs.docker.com/engine/api/v1.40/#tag/Container/operation/ContainerWait

Example:

curl -X POST http://localhost:8090/v4.2.0/libpod/containers/220b34da1552337c7bcb31a422f51407ce3bdb0748884d6f5f5c5f84e4f5efe5/wait
0

curl -X POST http://localhost:8090/v1.41/containers/220b34da1552337c7bcb31a422f51407ce3bdb0748884d6f5f5c5f84e4f5efe5/wait
{"StatusCode":0,"Error":null}

Inside api/client.py you can see the compatible_prefix, but if you specify that in the kwargs, it blows up if you use HTTPAdapter, because it doesn't allow the compatible_version kwarg. It then uses self.path_prefix and that's where it gets libpod from. I thought that might be a way to get this to work, but it did not.

       self.path_prefix = f"/v{self.version}/libpod/"
        self.compatible_version = kwargs.get("compatible_version", api.COMPATIBLE_VERSION)
        self.compatible_prefix = f"/v{self.compatible_version}/"

Below are some of the requests coming from podman-py.

127.0.0.1 - - [08/Sep/2022:17:02:16 -0500] "POST /v4.2.0/libpod/containers/3605caa5d93fe09515c5add54ee284df75e362e9286e2999f3863f1338ce9081/start HTTP/1.1" 204 0 "" "PodmanPy/4.2.0 (API v4.2.0; Compatible v1.40)"
127.0.0.1 - - [08/Sep/2022:17:02:16 -0500] "POST /v4.2.0/libpod/containers/3605caa5d93fe09515c5add54ee284df75e362e9286e2999f3863f1338ce9081/wait?condition=running&condition=exited HTTP/1.1" 200 2 "" "PodmanPy/4.2.0 (API v4.2.0; Compatible v1.40)"
127.0.0.1 - - [08/Sep/2022:17:02:16 -0500] "GET /v4.2.0/libpod/containers/3605caa5d93fe09515c5add54ee284df75e362e9286e2999f3863f1338ce9081/json HTTP/1.1" 200 4826 "" "PodmanPy/4.2.0 (API v4.2.0; Compatible v1.40)"
127.0.0.1 - - [08/Sep/2022:17:02:16 -0500] "GET /v4.2.0/libpod/containers/3605caa5d93fe09515c5add54ee284df75e362e9286e2999f3863f1338ce9081/logs?follow=True&stderr=False&stdout=True HTTP/1.1" 200 21 "" "PodmanPy/4.2.0 (API v4.2.0; Compatible v1.40)"
127.0.0.1 - - [08/Sep/2022:17:02:16 -0500] "POST /v4.2.0/libpod/containers/3605caa5d93fe09515c5add54ee284df75e362e9286e2999f3863f1338ce9081/wait HTTP/1.1" 200 2 "" "PodmanPy/4.2.0 (API v4.2.0; Compatible v1.40)"

@jonathanunderwood
Copy link
Contributor

This remains broken on master as of today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants