Skip to main content

Sandbox running code in Docker.

Project description

License: MIT made-with-python Open Source? Yes! PyTest

docker-lite-python

A simple, Python-based Docker interface built on top of the Docker SDK for Python. Intended to programmatically spin up, pass communications to, and ultimately tear down single Docker containers. Requires a local instance of Docker.

Installation | Quick Start | Reference | Examples

Installation:

pip install docker-lite-python

Quick Start:

$ sudo python3
>>>from docker_light_python import DockerLite
>>>dl = DockerLite()

start an Alpine container and keep it running

>>>dl.run_container('alpine:latest', 'alpine-container', 'sleep infinity')

exec into the running container

>>>dl.exec_into_running_container('alpine-container', 'echo "Hello World!"')
ExecResult(exit_code=0, output=b'Hello World!\n')

tear down that container!

>>>dl.kill_container('alpine-container')
0

Reference:

Methods Args Overview
build_image() *path_to_dir*: string: The path to the build directory. Build a Docker image from a local Dockerfile.
*resulting_image_name*: string Enforces best practice of explicitly naming images.
list_containers() *all*: bool: default=False List running containers by default.
run_container() *image_name*: string Run a Docker container, optionally with a command.
*resulting_container_name*: string Enforces best practice of explicitly naming containers.
*command*: string: The command to run. Optional.
get_container_by_name() *existing_container_name*: string Get a Docker container by name.
exec_into_running_container() *existing_container_name*: string Run a command in an active container.
*command*: string: The command to execute in the running Docker container.
list_images() None List all images in the local Docker instance.
remove_unused_images() None Equivalent of docker images prune
remove_all_images() None Force removal of all images. Purge system.
kill_container() *existing_container_name*: string Shut down and delete a container.
NOTE: kill_container() technically just stops the containers, as they are self-removing.

Examples:

from docker_lite import DockerLite

dl = DockerLite()

build image, 'my-image,' from a Dockerfile in the local directory

dl.build_image('./', 'my-image')

list all containers. Default is to list running containers

containers = dl.list_containers(all=True)

run a Docker container called 'my-container' based on a Docker image called 'my-image'

my_container = dl.run_container('my-image', 'my-container')

run a terminal command in a running Docker container called 'my-container'. Be creative

output = dl.exec_into_running_container('my-container', 'echo "Hello World!"')

get a container called 'my-container' by its unique name

container = dl.get_container('my-container')

kill a container called 'my-container' by its unique name

dl.kill_container('my-container')

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

docker-lite-python-1.0.6.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docker_lite_python-1.0.6-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file docker-lite-python-1.0.6.tar.gz.

File metadata

  • Download URL: docker-lite-python-1.0.6.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.3

File hashes

Hashes for docker-lite-python-1.0.6.tar.gz
Algorithm Hash digest
SHA256 1d67b7b5f109399c5b1d8b1283f653230c267c2c7309cdc93b9634bf62443d78
MD5 1fd186f25b03c5721ea17f36c2b058ca
BLAKE2b-256 8dffe38d0648bd26c62a6dedf13d8004b9347793d1863b17b095a3dfd19ab45b

See more details on using hashes here.

File details

Details for the file docker_lite_python-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: docker_lite_python-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.3

File hashes

Hashes for docker_lite_python-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5d77d86d72dc0cf69a696ddc07059a52d7bd63fc7937665ce0447cfadd8ff044
MD5 2cb8c8eb837f02329faf66a01261dde6
BLAKE2b-256 f8d8c63a77c30b51395b7f49ee9e2a86e9db4ad61bdd5a31f4dfc00a76de5f8a

See more details on using hashes here.

Supported by

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