Skip to content

Get live stdout of a running container #2697

@francoisihry

Description

@francoisihry

Hi,

I need to run a long time command in a container and print the stdout/stderr in live.

From what I have done so far I have to wait the end of the execution before being able to see the output logs.

For example, in the above code, I would like to be able to see "hello" before waiting the end of the 20secs:

import docker
client = docker.from_env()
container = client.containers.run('python:alpine', '''python -c "
                                import time; 
                                print('hello'); 
                                time.sleep(20); 
                                print('OK')"''',
                               detach=True, remove=True)

Many thanks for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions