tschm
tschm

Reputation: 2955

Docker run via subprocess

Ok, I am firing off some docker run commands via subprocess calls (in a GUI). The call looks like this:

import subprocess
a = subprocess.run(args, stdout=subprocess.PIPE)
output = a.stdout.decode().split("\n")

The process living in the docker container would log to the stdout and I thought I could then fetch my logging messages. I am using the docker run -a command, as in

/usr/bin/docker run --rm  -a stdout xxxx/pyrisk:latest python prices.py

Upvotes: 2

Views: 4344

Answers (1)

Jakub Bujny
Jakub Bujny

Reputation: 4628

I would suggest to use docker.py library instead of directly calling docker commands via subprocess. See more here: https://github.com/docker/docker-py

Your case would look like:

import docker
client = docker.from_env()
stdout = client.containers.run(image="xxxx/pyrisk:latest",command="python prices.py", remove=True)

Upvotes: 3

Related Questions