Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
K

kitchen-docker

> 数据库
Open source

A Test Kitchen Driver for Docker

462 stars0 likes0 views
WebsiteGitHub

About

A Test Kitchen Driver for Docker

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

Contents

  • Requirements
  • Installation
  • Quick start
  • How it works
  • Choosing an image and platform
  • Driver configuration
  • Transport configuration
  • Logging into a container
  • Other commands
  • Examples
  • Using with Chef
  • Troubleshooting
  • Contributing
  • License

Requirements

  • [Docker][docker_installation] 1.5 or newer, running locally or reachable over the network.
  • Ruby 3.1 or newer.

Installation

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:

bash
gem install kitchen-docker

Or add it to your cookbook's Gemfile:

ruby
gem "kitchen-docker"

Quick start

Create a kitchen.yml in your cookbook:

yaml
---
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:

bash
kitchen test

Test 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:

bash
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 up

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

How it works

Knowing the sequence makes the configuration options below much easier to place:

  1. Generate a Dockerfile. The driver writes one based on 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.
  2. Build the image, sending build_context (your cookbook directory) to the daemon if the daemon needs it.
  3. Run a container from the image with run_command as PID 1 — by default sshd, which keeps the container alive and gives Test Kitchen something to connect to.
  4. Run commands in it. With 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.

Choosing an image and platform

For most platforms, the name is all you need. The driver splits it on the first - into an image and a platform family:

yaml
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: fedora

centos 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:

yaml
platforms:
  - name: centos-stream-9
    driver:
      image: dokken/centos-stream-9
      platform: centosstream

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

Driver configuration

Everything in this section goes under driver: — either at the top level, or per-platform and per-suite:

yaml
driver:
  name: docker
  privileged: true          # applies everywhere

platforms:
  - name: ubuntu-24.04
    driver:
      forward:              # applies to this platform only
        - 8080:80

Images and building

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.

Provisioning the image

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.

Running the container

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.

Networking

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.

Storage

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.

Security and privileges

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.

Proxies

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.

Connecting to the Docker daemon

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

Issues· 18 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyhacktoberfestmanaged-by-terraformrubyruby-gem

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库