Skip to main content

Interact with Docker containers via Python-like APIs

Project description

https://travis-ci.org/ChrisTimperley/dockerblade.svg?branch=master https://badge.fury.io/py/dockerblade.svg https://img.shields.io/pypi/pyversions/dockerblade.svg https://coveralls.io/repos/github/ChrisTimperley/dockerblade/badge.svg

Dockerblade makes it easy to interact with Docker containers by providing an API, inspired by Python’s standard libraries (e.g., subprocess, os, and io) for executing commands and interacting with filesystems.

Installation

To install the latest release of dockerblade via pipenv or pip:

$ pipenv install dockerblade

Usage

To connect to a Docker daemon on the host machine and attach to a running container:

import dockerblade

daemon = dockerblade.DockerDaemon()
container = daemon.attach('name-of-the-container')

To perform filesystem operations on a container:

filesystem = container.filesystem()

# write text to a file
filesystem.write('/tmp/foo', 'Hello world!')

# remove a file (inspired by os.remove)
filesystem.remove('/tmp/foo')

# see API docs for more operations
...

To execute commands inside the container:

# specify the shell that should be used (e.g., /bin/sh, /bin/bash, /bin/zsh)
shell = container.shell('/bin/bash')

# obtain the value of an environment variable
val = container.environ('LD_LIBRARY_PATH')

# create a Popen
process = shell.popen('sleep 5')
retcode = process.wait()

# execute a command
assert shell.check_output('echo "Hello World"') == 'Hello World'

# see API docs for more operations
...

API Documentation

API documentation is available at: https://www.christimperley.co.uk/dockerblade

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dockerblade-0.6.0.tar.gz (20.0 kB view hashes)

Uploaded Source

Built Distribution

dockerblade-0.6.0-py3-none-any.whl (22.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page