dockerctx
dockerctx is a context manager for managing the lifetime of a docker container.
The main use case is for setting up scaffolding for running tests, where you want something a little broader than unit tests, but less heavily integrated than, say, what you might write using Robot framework.
Install
$ pip install dockerctx
The development-specific requirements will be installed automatically.
Demo
This is taken from one of the tests:
import time
import redis
import pytest
from dockerctx import new_container
# First make a pytest fixture
@pytest.fixture(scope='function')
def f_redis():
# This is the new thing! It's pretty clear. The `ready_test` provides
# a way to customize what "ready" means for each container. Here,
# we simply pause for a bit.
with new_container(
image_name='redis:latest',
ports={'6379/tcp': 56379},
ready_test=lambda: time.sleep(0.5) or True) as container:
yield container
# Here is the test. Since the fixture is at the "function" level, a fully
# new Redis container will be created for each test that uses this fixture.
# After the test completes, the container will be removed.
def test_redis_a(f_redis):
# The container object comes from the `docker` python package. Here we
# access only the "name" attribute, but there are many others.
print('Container %s' % f_redis.name)
r = redis.StrictRedis(host='localhost', port=56379, db=0)
r.set('foo', 'bar')
assert r.get('foo') == b'bar'
Note that a brand new Redis container is created here, used within the context of the context manager (which is wrapped into a pytest fixture here), and then the container is destroyed after the context manager exits.
In the src, there is another, much more elaborate test which
runs a postgres container;
waits for postgres to begin accepting connections;
creates a database;
creates tables (using the SQLAlchemy ORM);
performs database operations;
tears down and removes the container afterwards.
Metadata
Release files for dockerctx 2026.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dockerctx-2026.1.1.tar.gz | 5.4 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dockerctx-2026.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / dockerctx-2026.1.1.tar.gz
| Download URL | dockerctx-2026.1.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f6622d8470b14ca49ba12475edfdc321d3eb21259fd8b5fc5c6a1f46cc2244d5
|
|
BLAKE2b-256 checksum How to use checksums |
c749e342232ba7b5146f5df43ecce623a836e0301719954fb5b5903a3801f19c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2026.
Transparency logRelease files / dockerctx-2026.1.1-py3-none-any.whl
| Download URL | dockerctx-2026.1.1-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
99c66b2d448c6472f9bdc45c1babf177885478cfd941e123d6e5ef3878ce7a75
|
|
BLAKE2b-256 checksum How to use checksums |
cc4f3b69c679f10d48153dd6a326e6fd1ca44c21d6ea06b60edfa629d2b202db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2026.
Transparency logSecurity for dockerctx 2026.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for dockerctx-2026.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.