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

[question] how to use container's exec_run with stream enabled? #477

Open
343i opened this issue Nov 30, 2024 · 1 comment
Open

[question] how to use container's exec_run with stream enabled? #477

343i opened this issue Nov 30, 2024 · 1 comment

Comments

@343i
Copy link

343i commented Nov 30, 2024

Hi,

I'm trying to convert following snippet of my code that is using docker-py to for exec_run to stream the result:

docker:

  • code:
 exit_code, response = ubuntu_container.exec_run(cmd='apt-get install -y git docker.io neofetch', stream=True)
 
 for line in response:
     print(line.decode('utf-8').strip())
  • output:
Reading package lists...

Building dependency tree...
Reading state information...

docker.io is already the newest version (26.1.3-0ubuntu1).
neofetch is already the newest version (7.1.0-4).
Suggested packages:
  gettext-base git-daemon-run | git-daemon-sysvinit git-doc git-email git-gui
  gitk gitweb git-cvs git-mediawiki git-svn
The following NEW packages will be installed:
git
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 4045 kB of archives.
After this operation, 24.0 MB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports oracular/main arm64 git arm64 1:2.45.2-1ubuntu1 [4045 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 4045 kB in 4s (914 kB/s)
Selecting previously unselected package git.

podman:

  • code:
 exit_code, response = ubuntu_container.exec_run(cmd='apt-get install -y git docker.io neofetch', stream=True)
 
 for line in response:
     print(line) # changed as line.decode('utf-8').strip() throws AttributeError: 'int' object has no attribute 'decode'
  • output:
1
0
0
0
0
0
0
59
72
105
116
58
49
32
104

moreover the numbers that are returned in output are returned all at once in end, not in stream fashion,

I assume I'm doing this wrong by trying to force the docker way, can someone share sample code that is to be followed for stream responses

@inknos
Copy link
Contributor

inknos commented Dec 4, 2024

Hey, thanks this is worth investigating. I can't reproduce it with this code here.

from podman import PodmanClient

client = PodmanClient()
c = client.containers.create('ubuntu:latest', command=['sleep', '1000'], detach=True)
c.start()

exit_code response = c.exec_run(cmd='apt-get install -y git', stream=True)
for line in response:
     print(line.decode('utf-8').strip())

Output

Reading package lists...

Building dependency tree...
Reading state information...

E: Unable to locate package git

can you share more details of your reproducer? also, some versions will help me investigating the issue

  • podman version
  • podman-py version
  • python version
  • os

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

No branches or pull requests

2 participants