As the name of the repository suggests, it's just a playground. Will be used to start various test containers supported by Testcontainers in preparation for usage on various projects.
Note
You may need to enable "[x] Allow the default Docker socket to be used (requires password)" within your docker for desktop for containers to run successfully.
Install the necessary python packages in requirements.txt
:
pip install requirements.txt
And then run any of the tests within the project:
pytest tests
Tests can also be run within an integration environment (e.g. Jenkins, GitHub, Azure Pipelines etc.) two things have to be provided:
-
The container has to provide a docker client installation. Either use an image that has docker pre-installed (e.g. the official docker images) or install the client from within the Dockerfile specification.
-
The container has to have access to the docker daemon which can be achieved by mounting
/var/run/docker.sock
or setting theDOCKER_HOST
environment variable as part of your docker run command.
Environment Variable | Example | Description |
---|---|---|
TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE | /var/run/docker.sock | Path to Docker’s socket used by ryuk |
TESTCONTAINERS_RYUK_PRIVILEGED | false | Run ryuk as a privileged container |
TESTCONTAINERS_RYUK_DISABLED | false | Disable ryuk |
RYUK_CONTAINER_IMAGE | testcontainers/ryuk:0.7.0 | Custom image for ryuk |
Build the docker image using the Dockerfile
provided and then run the container:
docker build -t testcontainers-python:example .
docker run -i -e TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock \
-e TESTCONTAINERS_RYUK_PRIVILEGED=false \
-e TESTCONTAINERS_RYUK_DISABLED=false \
-e RYUK_CONTAINER_IMAGE=testcontainers/ryuk:0.7.0 \
-v /var/run/docker.sock:/var/run/docker.sock \
--name testcontainers-example testcontainers-python:example