Run Chaos Toolkit locally with Docker¶
Docker is a fantastic approach to package up your Chaos Toolkit experiment dependencies and make it easy for anyone to run your experiments.
Official Images¶
Chaos Toolkit offers three base images you can use.
chaostoolkit/chaostoolkit:latest
This is an Alpine based image and does not contain any extensionschaostoolkit/chaostoolkit:basic
This is an Ubuntu based image and does not contain any extensionschaostoolkit/chaostoolkit:full
This is an Ubuntu based image and does contains many popular extensions
Create your Own Container Image¶
While an image such as chaostoolkit/chaostoolkit:full
is a good default to start with, you will likely want to create your own image with specific extensions and dependencies for your needs.
Let’s see how to get on about it.
FROM chaostoolkit/chaostoolkit:basic
COPY pyproject.toml pdm.lock /home/svc/
USER root
WORKDIR /home/svc
RUN apt-get update && \
apt-get install -y --no-install-recommends curl python3.11-venv build-essential gcc && \
curl -o install-pdm.py -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py && \
python3.11 install-pdm.py -p /home/svc && \
export PATH=/home/svc/bin:$PATH && \
pdm use .venv && \
pdm install --no-editable --no-self && \
rm install-pdm.py && \
chown --recursive svc:svc /home/svc/.venv && \
apt-get remove -y build-essential gcc && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
USER 1001
Before you can create your image, you now need to create a pyproject.toml
file listing the dependencies you wish to install. Here a basic one:
[project]
name = "my-experiment"
version = "0.1.0"
dependencies = []
requires-python = ">=3.11"
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"
[tool.pdm]
distribution = false
To add dependencies, run the following command:
pdm add chaostoolkit-kubernetes
Tip
Install pdm
from pdm.
The first time this command is run, it generates the pdm.lock
file describing the specific version to install.
We’re done!
You can now create the image with:
docker build -t my/chaostoolkit .
Once this image has been published to a container registry, it is available to use by anyone with access or from other environments such as Kubernetes or serverless providers.
Run an Experiment¶
Let’s assume you have this Chaos Toolkit experiment:
{
"version": "1.0.0",
"title": "Hello world!",
"description": "Say hello to the world.",
"method": [
{
"type": "action",
"name": "say-hello",
"provider": {
"type": "process",
"path": "echo",
"arguments": "hello"
}
}
]
}
You can run this experiment as follows:
docker run -v `pwd`/experiment.json:/home/svc/experiment.json my/chaostoolkit run experiment.json