Interact with Docker containers via Python-like APIs
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dockerblade-0.6.3.tar.gz
.
File metadata
- Download URL: dockerblade-0.6.3.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.2 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8250e89ba7d24c26c47641ed4481827d46bc18aae8700e8a17fb76410470d91f |
|
MD5 | e7cfb238c4d02be719069a97abddd237 |
|
BLAKE2b-256 | 72231ce36ebfe27b491b90be9ca85758153444c2a08f51d71639e2743bb8e40c |
File details
Details for the file dockerblade-0.6.3-py3-none-any.whl
.
File metadata
- Download URL: dockerblade-0.6.3-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.2 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17721034afce3999efbfa0f9e27292eb1b7dc05b1e43e2075e02250c03a803b0 |
|
MD5 | 0ac7c246020e0281e34c8a89f8771ac5 |
|
BLAKE2b-256 | 2254f714558cdcd99800a24867b51701d0a987ce228e05844aed20a7a81c373c |