A Test Kitchen Driver for Docker
A [Test Kitchen][test_kitchen_docs] driver and transport for Docker.
The driver builds an image for each platform and runs a container from it. The
transport runs your commands inside that container with docker exec, so no
SSH or WinRM server is needed. Together they let you converge and verify a
cookbook against a dozen distributions in about the time it takes one virtual
machine to boot.
Maintainers wanted. This driver is currently without a maintainer and has known issues. If you would like to take it on — including expanding the CI coverage — please reach out in #test-kitchen on Chef Community Slack. Until then, we recommend [kitchen-dokken][dokken] for Chef Infra testing with Docker containers.
This driver ships as part of [Cinc Workstation][cinc_workstation] and [Chef Workstation][chef_workstation]. If you have either installed, there is nothing else to do.
To install it into a standalone Ruby:
gem install kitchen-dockerOr add it to your cookbook's Gemfile:
gem "kitchen-docker"Create a kitchen.yml in your cookbook:
---
driver:
name: docker
transport:
name: docker
provisioner:
name: cinc_infra
verifier:
name: cinc_auditor
platforms:
- name: ubuntu-24.04
- name: almalinux-9
suites:
- name: default
run_list:
- recipe[my_cookbook::default]That is a complete configuration — no image, no platform, no
run_command. The driver derives them from each platform name.
Run it:
kitchen testTest Kitchen will, for each platform, build an image, start a container, converge your cookbook, run the verifier, and destroy the container. To work interactively instead:
kitchen converge default-ubuntu-2404 # build, start, and converge
kitchen login default-ubuntu-2404 # get a shell inside the container
kitchen verify default-ubuntu-2404 # run the tests
kitchen destroy default-ubuntu-2404 # clean upThe examples above use the cinc_infra provisioner and cinc_auditor
verifier. If you use Chef Workstation, substitute chef_infra and inspec —
see Using with Chef. No driver changes are needed.
Knowing the sequence makes the configuration options below much easier to place:
image and
platform: it installs an SSH server and sudo, creates the username
account, and authorises the generated public_key. Anything in
provision_command is appended. Supply your own with
dockerfile to skip all of this.build_context (your cookbook directory) to
the daemon if the daemon needs it.run_command as PID 1 — by default
sshd, which keeps the container alive and gives Test Kitchen something to
connect to.transport: docker this is docker exec. With
the default SSH transport, it is SSH to the forwarded port using the
generated key.Because the image is rebuilt from a Dockerfile, most driver options are
image-level (build_options, provision_command) or container-level
(volume, privileged, forward). The tables below are grouped that way.
For most platforms, the name is all you need. The driver splits it on the first
- into an image and a platform family:
platforms:
- name: ubuntu-24.04 # image: ubuntu:24.04, platform: ubuntu
- name: almalinux-9 # image: almalinux:9, platform: almalinux
- name: fedora-latest # image: fedora:latest, platform: fedoracentos is special-cased, because its images are tagged centos7 rather than
centos:7.
Set image and platform explicitly when the image name does not match the
distribution, which is common for vendor or mirror images:
platforms:
- name: centos-stream-9
driver:
image: dokken/centos-stream-9
platform: centosstreamplatform selects how the Dockerfile bootstraps the container, so it must be
one the driver recognises:
platform |
Notes |
|---|---|
debian, ubuntu |
Also honours disable_upstart. |
rhel, centos, oraclelinux |
Shared RHEL package set. |
almalinux, rockylinux, centosstream |
RHEL rebuilds, each with its own package set. |
amazonlinux |
Adds --allowerasing to dnf install. |
fedora |
|
arch |
|
gentoo, gentoo-paludis |
|
opensuse, opensuse/leap, opensuse/tumbleweed, sles |
|
photon |
|
windows |
Uses Windows containers; see Windows containers. |
Anything else raises Unknown platform ''. If your distribution is not
listed, supply your own dockerfile instead.
Everything in this section goes under driver: — either at the top level, or
per-platform and per-suite:
driver:
name: docker
privileged: true # applies everywhere
platforms:
- name: ubuntu-24.04
driver:
forward: # applies to this platform only
- 8080:80| Option | Default | Description |
|---|---|---|
image |
derived from the platform name | Base image for the container. |
platform |
derived from the platform name | Distribution family, used to bootstrap the image. See above. |
dockerfile |
(none) | Path to your own Dockerfile, used instead of the generated one. Rendered as ERB. |
build_context |
true locally, false for a remote daemon |
Send the working directory to the daemon as build context. Required for ADD and COPY; slow against a remote daemon. |
build_options |
(none) | Extra flags for docker build, as a string or a map. |
build_tempdir |
working directory | Directory the generated Dockerfile is written to. A relative path is resolved against the working directory, and the path must be inside the build context, since docker build -f is given it relative to the working directory. |
use_cache |
true |
Use Docker's build cache. false adds --no-cache. |
remove_images |
false |
Remove the built image on kitchen destroy. |
package_name |
the instance name, tagged latest |
Image kitchen package commits the container to. |
docker_platform |
(none) | Target architecture, passed as --platform to both build and run — e.g. linux/arm64. |
| Option | Default | Description |
|---|---|---|
provision_command |
(none) | Command, or list of commands, to run while building the image. Each becomes a RUN line. |
disable_upstart |
true |
Neutralise upstart on Debian and Ubuntu images that ship a broken copy. Ignored on other platforms. |
username |
kitchen on Linux, unset on Windows |
Account created in the image and used for the connection. |
private_key |
.kitchen/docker_id_rsa |
SSH key used to reach the container. Generated on first use if absent. |
public_key |
.kitchen/docker_id_rsa.pub |
Matching public key, authorised in the image. |
| Option | Default | Description |
|---|---|---|
run_command |
sshd -D … on Linux, ping -t localhost on Windows |
Process run as PID 1. It must stay in the foreground, or the container will exit immediately. |
run_options |
(none) | Extra flags for docker run, as a string or a map. |
instance_name |
generated, unique | --name for the container. Set it to give other containers a stable name to link to. |
hostname |
Docker's default | Container hostname. |
memory |
Docker's default | Memory limit in bytes. |
cpu |
Docker's default | CPU shares (relative weight). |
gpus |
(none) | Passed as --gpus. Requires a GPU-enabled Docker installation. |
isolation |
Docker's default | Isolation technology — hyperv or process for Windows containers. |
interactive |
false |
Pass -i, keeping stdin open. |
tty |
false |
Pass -t, allocating a pseudo-TTY. |
env_variables |
(none) | Environment variables set in the container, as a map. |
wait_for_transport |
true |
Wait for the transport to answer before converging. Set false for containers that do not stay up. |
The container itself is always started detached — see detach
under the transport for how provisioner commands are run.
| Option | Default | Description |
|---|---|---|
forward |
(none) | Ports to publish, as container or host:container. Docker picks the host port if you omit it. |
publish_all |
false |
Publish every exposed port to a random host port (-P). |
dns |
Docker's default | DNS servers for the container. |
add_host |
(none) | Extra /etc/hosts entries, as a map of hostname to IP. |
links |
(none) | Other containers to link, as name:alias. |
use_internal_docker_network |
false |
Connect over the container's own IP on port 22 instead of a forwarded host port. Needed when Test Kitchen itself runs inside a container. |
| Option | Default | Description |
|---|---|---|
volume |
(none) | Volumes to add, in docker run -v syntax. |
volumes_from |
(none) | Containers whose volumes to mount. |
mount |
(none) | Mounts in --mount syntax. Requires Docker 17.05 or newer. |
tmpfs |
(none) | tmpfs mounts, e.g. /tmp or /tmp:exec. |
devices |
(none) | Host devices to share. Must be absolute paths. |
Each of these accepts a single value or a list.
| Option | Default | Description |
|---|---|---|
privileged |
false |
Run the container privileged. Needed for systemd, Docker-in-Docker, and some kernel-level tests. |
cap_add |
(none) | Capabilities to add, e.g. SYS_PTRACE. |
cap_drop |
(none) | Capabilities to drop. |
security_opt |
(none) | SELinux or AppArmor profiles — finer-grained than privileged. |
| Option | Default | Description |
|---|---|---|
http_proxy |
(none) | Set as http_proxy and HTTP_PROXY, both in the image and in the running container. |
https_proxy |
(none) | Set as https_proxy and HTTPS_PROXY, in the image and the container. |
no_proxy |
(none) | Set as no_proxy and NO_PROXY in the image only, for use during the build. |
| Option | Default | Description |
|---|---|---|
binary |
docker |
Docker CLI to invoke — e.g. docker.io, or an absolute path. |
socket |
$DOCKER_HOST, else unix:///var/run/docker.sock (npipe:////./pipe/docker_engine on Windows) |
Daemon to talk to. A tcp:// value also supplies the host used for SSH to the container. |
use_sudo |
false |
Run every docker command through sudo. |
sudo_command |
sudo -E |
The command use_sudo prefixes, for hosts that use something else (doas, say). |
tls |
false |
Use TLS when connecting. |
tls_verify |
false |
No open issues yet, or sync has not completed.