docker/docker-py — pull request #363 by phensley (2014-10-17 20:15:12+00:00)
Title: Added the exec command for Docker 1.3.0

To use, start a container:

% docker run -it --name shell busybox sh

Then execute a command in the running container using the Python client:

#!/usr/bin/env python

import os, sys
import docker

cli = docker.Client(os.environ['DOCKER_HOST'], version='1.15')

name = sys.argv[1]
cmd = sys.argv[2:]

print cli.execute(name, cmd, stdout=True, stderr=True, tty=False)

Example:

% ./exec_test shell ls -1
bin
dev
etc
home
lib
lib64
...