https://github.com/christimperley/dockerblade
An API for performing Python standard library operations on Docker containers (e.g., subprocess, io, os, shutil).
https://github.com/christimperley/dockerblade
docker python
Last synced: 3 months ago
JSON representation
An API for performing Python standard library operations on Docker containers (e.g., subprocess, io, os, shutil).
- Host: GitHub
- URL: https://github.com/christimperley/dockerblade
- Owner: ChrisTimperley
- License: apache-2.0
- Created: 2019-10-12T19:03:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-20T22:54:25.000Z (about 2 years ago)
- Last Synced: 2024-05-21T00:24:07.840Z (about 2 years ago)
- Topics: docker, python
- Language: Python
- Homepage: https://www.christimperley.co.uk/dockerblade/
- Size: 421 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 21
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE
Awesome Lists containing this project
README
.. -*-restructuredtext-*-
dockerblade
===========
.. image:: https://badge.fury.io/py/dockerblade.svg
:target: https://badge.fury.io/py/dockerblade
.. image:: https://img.shields.io/pypi/pyversions/dockerblade.svg
:target: https://pypi.org/project/dockerblade
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 :code:`pip`:
.. code:: console
$ pipenv install dockerblade
Usage
-----
To connect to a Docker daemon on the host machine and attach to a running
container:
.. code:: python
import dockerblade
daemon = dockerblade.DockerDaemon()
container = daemon.attach('name-of-the-container')
To perform filesystem operations on a container:
.. code:: python
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:
.. code:: python
# 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