Skip to content

🛝 \ ˈplā-ˌgrau̇nd \ an area known or suited for activity of a specified sort.

Notifications You must be signed in to change notification settings

kwame-mintah/testcontainers-python-playground

Repository files navigation

🛝 Testcontainers Python Playground

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.

Prerequisites

  1. Docker for desktop

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.

Usage

Install the necessary python packages in requirements.txt:

pip install requirements.txt

And then run any of the tests within the project:

pytest tests

Running Docker in Docker (DinD)

Tests can also be run within an integration environment (e.g. Jenkins, GitHub, Azure Pipelines etc.) two things have to be provided:

  1. 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.

  2. The container has to have access to the docker daemon which can be achieved by mounting /var/run/docker.sock or setting the DOCKER_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

About

🛝 \ ˈplā-ˌgrau̇nd \ an area known or suited for activity of a specified sort.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published