0

I have pulled alpine image I have build the container I am trying run the image but I do not see any output on my console, anyone whats wrong? If I run using docker run I can see the output

Python version is 2.7.10

dockerClient = docker.from_env()
image = dockerClient.images.pull(alpine)
dockerClient.images.build(path = "build/", tag="alpine_tests")
dockerClient.containers.run('alpine_tests', 'pwd')
user2511126
  • 620
  • 1
  • 14
  • 31
  • You're making an API call (not unlike what you could do with `requests` for example). Nothing will get printed to the console unless you print it yourself. – David Maze Feb 14 '19 at 02:40
  • ok.. thanks.. I need to print it explicitly – user2511126 Feb 14 '19 at 03:36
  • I am trying to run a script inside docker and output of the script is printed using "dcoker run.." but doesnt print when I use python apis using print statement. – user2511126 Feb 16 '19 at 11:11

1 Answers1

0

If you really want to see information immediately, you should use docker build in CLI, or subproccess.call(['docker', 'build']) in Python.

When using the Python SDK, the stdout and stderr messages are always not necessary when success. Only when crashed or failed, messages are good.

# docker build
client = docker.from_env()
try:
    client.images.build(
        path='build/',
        tag='alpine_tests',
    )
except docker.errors.BuildError as exc:
    for log in exc.build_log:
        msg = log.get('stream')
        if msg:
            print(msg, end='')
    raise

# docker push
ret = client.images.push(alpine_tests)
last_line = ret.splitlines()[-1]
info = json.loads(last_line)
error = info.get('error')
if error:
    print(error)
    exit(1)
Yan QiDong
  • 3,696
  • 1
  • 24
  • 25