Search code examples
pythondockerdockerpy

Using pipes with docker-py


In the example at https://github.com/docker/docker-py, they return the results of a command to a docker image as so:

>>> client.containers.run("ubuntu:latest", "echo hello world")
'hello world\n'

What I want is to use a pipe - for instance, it would be great if I could do this:

>>> client.containers.run("ubuntu:latest", "echo hello world | wc")
'       1       2      12\n'

However, instead I get this:

 >>> client.containers.run("ubuntu:latest", "echo hello world | wc")
    b'hello world | wc\n'

What is the easiest way to run two commands, the second piped from the first, in docker?


Solution

  • It is simply :

    client.containers.run("ubuntu:latest", "sh -c 'echo hello world | wc'")