kitchen-docker 3.3.0 → 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,687 +1,571 @@
1
- # Kitchen-Docker
1
+ # kitchen-docker
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/kitchen-docker.svg)](https://rubygems.org/gems/kitchen-docker)
4
- [![Coverage](https://img.shields.io/codecov/c/github/test-kitchen/kitchen-docker.svg)](https://codecov.io/github/test-kitchen/kitchen-docker)
5
4
  [![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
6
5
 
7
- A Test Kitchen Driver and Transport for Docker.
8
-
9
- ***MAINTAINERS WANTED***: This Test-Kitchen driver is currently without a maintainer and has many known issues. If you're interested in maintaining this driver for the long run including expanding the CI testing please reach out on [Chef Community Slack: #test-kitchen](https://chefcommunity.slack.com/archives/C2B6G1WCQ). Until such a time that this driver is maintained we highly recommend the [kitchen-dokken](https://github.com/test-kitchen/kitchen-dokken) for Chef Infra testing with Docker containers.
6
+ A [Test Kitchen][test_kitchen_docs] **driver** and **transport** for Docker.
7
+
8
+ The driver builds an image for each platform and runs a container from it. The
9
+ transport runs your commands inside that container with `docker exec`, so no
10
+ SSH or WinRM server is needed. Together they let you converge and verify a
11
+ cookbook against a dozen distributions in about the time it takes one virtual
12
+ machine to boot.
13
+
14
+ > **Maintainers wanted.** This driver is currently without a maintainer and has
15
+ > known issues. If you would like to take it on — including expanding the CI
16
+ > coverage — please reach out in
17
+ > [#test-kitchen on Chef Community Slack](https://chefcommunity.slack.com/archives/C2B6G1WCQ).
18
+ > Until then, we recommend [kitchen-dokken][dokken] for Chef Infra testing with
19
+ > Docker containers.
20
+
21
+ ## Contents
22
+
23
+ * [Requirements](#requirements)
24
+ * [Installation](#installation)
25
+ * [Quick start](#quick-start)
26
+ * [How it works](#how-it-works)
27
+ * [Choosing an image and platform](#choosing-an-image-and-platform)
28
+ * [Driver configuration](#driver-configuration)
29
+ * [Transport configuration](#transport-configuration)
30
+ * [Logging into a container](#logging-into-a-container)
31
+ * [Examples](#examples)
32
+ * [Using with Chef](#using-with-chef)
33
+ * [Troubleshooting](#troubleshooting)
34
+ * [Contributing](#contributing)
35
+ * [License](#license)
10
36
 
11
37
  ## Requirements
12
38
 
13
- * [Docker][docker_installation] **(>= 1.5)**
39
+ * [Docker][docker_installation] 1.5 or newer, running locally or reachable over
40
+ the network.
41
+ * Ruby 3.1 or newer.
14
42
 
15
- ## Installation and Setup
43
+ ## Installation
16
44
 
17
- Please read the Test Kitchen [docs][test_kitchen_docs] for more details.
45
+ This driver ships as part of [Cinc Workstation][cinc_workstation] and
46
+ [Chef Workstation][chef_workstation]. If you have either installed, there is
47
+ nothing else to do.
18
48
 
19
- Example (Linux) `.kitchen.local.yml`:
49
+ To install it into a standalone Ruby:
20
50
 
21
- ```yaml
22
- ---
23
- driver:
24
- name: docker
25
- env_variables:
26
- TEST_KEY: TEST_VALUE
51
+ ```sh
52
+ gem install kitchen-docker
53
+ ```
27
54
 
28
- platforms:
29
- - name: ubuntu
30
- run_list:
31
- - recipe[apt]
32
- - name: centos
33
- driver_config:
34
- image: centos
35
- platform: rhel
36
- run_list:
37
- - recipe[yum]
55
+ Or add it to your cookbook's `Gemfile`:
38
56
 
39
- transport:
40
- name: docker
57
+ ```ruby
58
+ gem "kitchen-docker"
41
59
  ```
42
60
 
43
- Example (Windows) `.kitchen.local.yml`:
61
+ ## Quick start
62
+
63
+ Create a `kitchen.yml` in your cookbook:
44
64
 
45
65
  ```yaml
46
66
  ---
47
67
  driver:
48
68
  name: docker
49
69
 
50
- platforms:
51
- - name: windows
52
- driver_config:
53
- image: mcr.microsoft.com/windows/servercore:1607
54
- platform: windows
55
- run_list:
56
- - recipe[chef_client]
57
-
58
70
  transport:
59
71
  name: docker
60
- env_variables:
61
- TEST_KEY: TEST_VALUE
62
- ```
63
-
64
- ## Default Configuration
65
72
 
66
- This driver can determine an image and platform type for a select number of
67
- platforms.
73
+ provisioner:
74
+ name: cinc_infra
68
75
 
69
- Examples:
76
+ verifier:
77
+ name: cinc_auditor
70
78
 
71
- ```yaml
72
- ---
73
- platforms:
74
- - name: ubuntu-18.04
75
- - name: centos-7
76
- ```
77
-
78
- This will effectively generate a configuration similar to:
79
-
80
- ```yaml
81
- ---
82
79
  platforms:
83
- - name: ubuntu-18.04
84
- driver_config:
85
- image: ubuntu:18.04
86
- platform: ubuntu
87
- - name: centos-7
88
- driver_config:
89
- image: centos:7
90
- platform: centos
91
- ```
92
-
93
- ## Configuration
94
-
95
- ### binary
96
-
97
- The Docker binary to use.
98
-
99
- The default value is `docker`.
100
-
101
- Examples:
102
-
103
- ```yaml
104
- binary: docker.io
105
- ```
106
-
107
- ```yaml
108
- binary: /opt/docker
109
- ```
110
-
111
- ### socket
112
-
113
- The Docker daemon socket to use. By default, Docker will listen on `unix:///var/run/docker.sock` (On Windows, `npipe:////./pipe/docker_engine`),
114
- and no configuration here is required. If Docker is binding to another host/port or Unix socket, you will need to set this option.
115
- If a TCP socket is set, its host will be used for SSH access to suite containers.
116
-
117
- Examples:
118
-
119
- ```yaml
120
- socket: unix:///tmp/docker.sock
121
- ```
122
-
123
- ```yaml
124
- socket: tcp://docker.example.com:4242
125
- ```
126
-
127
- If you are using the InSpec verifier on Windows, using named pipes for the Docker engine will not work with the Docker transport.
128
- Set the socket option with the TCP socket address of the Docker engine as shown below:
129
-
130
- ```yaml
131
- socket: tcp://localhost:2375
132
- ```
133
-
134
- The Docker engine must be configured to listen on a TCP port (default port is 2375). This can be configured by editing the configuration file
135
- (usually located in `C:\ProgramData\docker\config\daemon.json`) and adding the hosts value:
136
-
137
- ```json
138
- "hosts": ["tcp://0.0.0.0:2375"]
139
- ```
140
-
141
- Example configuration is shown below:
142
-
143
- ```json
144
- {
145
- "registry-mirrors": [],
146
- "insecure-registries": [],
147
- "debug": true,
148
- "experimental": false,
149
- "hosts": ["tcp://0.0.0.0:2375"]
150
- }
151
- ```
80
+ - name: ubuntu-24.04
81
+ - name: almalinux-9
152
82
 
153
- If you use [Boot2Docker](https://github.com/boot2docker/boot2docker)
154
- or [docker-machine](https://docs.docker.com/machine/get-started/) set
155
- your `DOCKER_HOST` environment variable properly with `export
156
- DOCKER_HOST=tcp://192.168.59.103:2375` or `eval "$(docker-machine env
157
- $MACHINE)"` then use the following:
158
-
159
- ```yaml
160
- socket: tcp://192.168.59.103:2375
161
- ```
162
-
163
- ### image
164
-
165
- The Docker image to use as the base for the suite containers. You can find
166
- images using the [Docker Index][docker_index].
167
-
168
- The default will be computed, using the platform name (see the Default
169
- Configuration section for more details).
170
-
171
- ### isolation
172
-
173
- The isolation technology for the container. This is not set by default and will use the default container isolation settings.
174
-
175
- For example, the following driver configuration options can be used to specify the container isolation technology for Windows containers:
176
-
177
- ```yaml
178
- # Hyper-V
179
- isolation: hyperv
180
-
181
- # Process
182
- isolation: process
183
- ```
184
-
185
- ### platform
186
-
187
- The platform of the chosen image. This is used to properly bootstrap the
188
- suite container for Test Kitchen. Kitchen Docker currently supports:
189
-
190
- * `arch`
191
- * `debian` or `ubuntu`
192
- * `amazonlinux`, `rhel`, `centos`, `fedora`, `oraclelinux`, `almalinux` or `rockylinux`
193
- * `gentoo` or `gentoo-paludis`
194
- * `opensuse/tumbleweed`, `opensuse/leap`, `opensuse` or `sles`
195
- * `windows`
196
-
197
- The default will be computed, using the platform name (see the Default
198
- Configuration section for more details).
199
-
200
- ### require\_chef\_omnibus
201
-
202
- Determines whether or not a Chef [Omnibus package][chef_omnibus_dl] will be
203
- installed. There are several different behaviors available:
204
-
205
- * `true` - the latest release will be installed. Subsequent converges
206
- will skip re-installing if chef is present.
207
- * `latest` - the latest release will be installed. Subsequent converges
208
- will always re-install even if chef is present.
209
- * `<VERSION_STRING>` (ex: `10.24.0`) - the desired version string will
210
- be passed the the install.sh script. Subsequent converges will skip if
211
- the installed version and the desired version match.
212
- * `false` or `nil` - no chef is installed.
213
-
214
- The default value is `true`.
215
-
216
- ### disable\_upstart
217
-
218
- Disables upstart on Debian/Ubuntu containers, as many images do not support a
219
- working upstart.
220
-
221
- The default value is `true`.
222
-
223
- ### provision\_command
224
-
225
- Custom command(s) to be run when provisioning the base for the suite containers.
226
-
227
- Examples:
228
-
229
- ```yaml
230
- provision_command: curl -L https://www.opscode.com/chef/install.sh | bash
83
+ suites:
84
+ - name: default
85
+ run_list:
86
+ - recipe[my_cookbook::default]
231
87
  ```
232
88
 
233
- ```yaml
234
- provision_command:
235
- - apt-get install dnsutils
236
- - apt-get install telnet
237
- ```
238
-
239
- ```yaml
240
- driver_config:
241
- provision_command: curl -L https://www.opscode.com/chef/install.sh | bash
242
- require_chef_omnibus: false
243
- ```
244
-
245
- ### env_variables
89
+ That is a complete configuration — no `image`, no `platform`, no
90
+ `run_command`. The driver derives them from each platform name.
246
91
 
247
- Adds environment variables to Docker container
92
+ Run it:
248
93
 
249
- Examples:
250
-
251
- ```yaml
252
- env_variables:
253
- TEST_KEY_1: TEST_VALUE
254
- SOME_VAR: SOME_VALUE
94
+ ```sh
95
+ kitchen test
255
96
  ```
256
97
 
257
- ### use\_cache
258
-
259
- This determines if the Docker cache is used when provisioning the base for suite
260
- containers.
261
-
262
- The default value is `true`.
263
-
264
- ### use\_sudo
265
-
266
- This determines if Docker commands are run with `sudo`.
267
-
268
- The default value depends on the type of socket being used. For local sockets, the default value is `true`. For remote sockets, the default value is `false`.
269
-
270
- This should be set to `false` if you're using boot2docker, as every command passed into the VM runs as root by default.
271
-
272
- ### remove\_images
98
+ Test Kitchen will, for each platform, build an image, start a container,
99
+ converge your cookbook, run the verifier, and destroy the container. To work
100
+ interactively instead:
273
101
 
274
- This determines if images are automatically removed when the suite container is
275
- destroyed.
276
-
277
- The default value is `false`.
278
-
279
- ### run\_command
280
-
281
- Sets the command used to run the suite container.
282
-
283
- The default value is `/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no -o PasswordAuthentication=yes -o UsePrivilegeSeparation=no -o PidFile=/tmp/sshd.pid`.
284
-
285
- Examples:
286
-
287
- ```yaml
288
- run_command: /sbin/init
102
+ ```sh
103
+ kitchen converge default-ubuntu-2404 # build, start, and converge
104
+ kitchen login default-ubuntu-2404 # get a shell inside the container
105
+ kitchen verify default-ubuntu-2404 # run the tests
106
+ kitchen destroy default-ubuntu-2404 # clean up
289
107
  ```
290
108
 
291
- ### memory
109
+ The examples above use the `cinc_infra` provisioner and `cinc_auditor`
110
+ verifier. If you use Chef Workstation, substitute `chef_infra` and `inspec` —
111
+ see [Using with Chef](#using-with-chef). No driver changes are needed.
292
112
 
293
- Sets the memory limit for the suite container in bytes. Otherwise use Dockers
294
- default. You can read more about `memory.limit_in_bytes` in the [Resource Management Guide][memory_limit].
295
-
296
- ### cpu
297
-
298
- Sets the CPU shares (relative weight) for the suite container. Otherwise use
299
- Dockers defaults. You can read more about cpu.shares in the [Resource Management Guide][cpu_shares].
300
-
301
- ### volume
302
-
303
- Adds a data volume(s) to the suite container.
304
-
305
- Examples:
306
-
307
- ```yaml
308
- volume: /ftp
309
- ```
113
+ ## How it works
310
114
 
311
- ```yaml
312
- volume:
313
- - /ftp
314
- - /srv
315
- ```
115
+ Knowing the sequence makes the configuration options below much easier to
116
+ place:
316
117
 
317
- ### volumes\_from
118
+ 1. **Generate a Dockerfile.** The driver writes one based on `image` and
119
+ `platform`: it installs an SSH server and `sudo`, creates the `username`
120
+ account, and authorises the generated `public_key`. Anything in
121
+ `provision_command` is appended. Supply your own with
122
+ [`dockerfile`](#images-and-building) to skip all of this.
123
+ 2. **Build the image**, sending `build_context` (your cookbook directory) to
124
+ the daemon if the daemon needs it.
125
+ 3. **Run a container** from the image with `run_command` as PID 1 — by default
126
+ `sshd`, which keeps the container alive and gives Test Kitchen something to
127
+ connect to.
128
+ 4. **Run commands in it.** With `transport: docker` this is `docker exec`. With
129
+ the default SSH transport, it is SSH to the forwarded port using the
130
+ generated key.
318
131
 
319
- Mount volumes managed by other containers.
132
+ Because the image is rebuilt from a Dockerfile, most driver options are
133
+ *image*-level (`build_options`, `provision_command`) or *container*-level
134
+ (`volume`, `privileged`, `forward`). The tables below are grouped that way.
320
135
 
321
- Examples:
136
+ ## Choosing an image and platform
322
137
 
323
- ```yaml
324
- volumes_from: repos
325
- ```
138
+ For most platforms, the name is all you need. The driver splits it on the first
139
+ `-` into an image and a platform family:
326
140
 
327
141
  ```yaml
328
- volumes_from:
329
- - repos
330
- - logging
331
- - rvm
142
+ platforms:
143
+ - name: ubuntu-24.04 # image: ubuntu:24.04, platform: ubuntu
144
+ - name: almalinux-9 # image: almalinux:9, platform: almalinux
145
+ - name: fedora-latest # image: fedora:latest, platform: fedora
332
146
  ```
333
147
 
334
- ### mount
148
+ `centos` is special-cased, because its images are tagged `centos7` rather than
149
+ `centos:7`.
335
150
 
336
- Attach a filesystem mount to the container (**NOTE:** supported only in docker
337
- 17.05 and newer).
338
-
339
- Examples:
151
+ Set `image` and `platform` explicitly when the image name does not match the
152
+ distribution, which is common for vendor or mirror images:
340
153
 
341
154
  ```yaml
342
- mount: type=volume,source=my-volume,destination=/path/in/container
155
+ platforms:
156
+ - name: centos-stream-9
157
+ driver:
158
+ image: dokken/centos-stream-9
159
+ platform: centosstream
343
160
  ```
344
161
 
345
- ```yaml
346
- mount:
347
- - type=volume,source=my-volume,destination=/path/in/container
348
- - type=tmpfs,tmpfs-size=512M,destination=/path/to/tmpdir
349
- ```
162
+ `platform` selects how the Dockerfile bootstraps the container, so it must be
163
+ one the driver recognises:
350
164
 
351
- ### tmpfs
165
+ | `platform` | Notes |
166
+ | --- | --- |
167
+ | `debian`, `ubuntu` | Also honours [`disable_upstart`](#provisioning-the-image). |
168
+ | `rhel`, `centos`, `oraclelinux` | Shared RHEL package set. |
169
+ | `almalinux`, `rockylinux`, `centosstream` | RHEL rebuilds, each with its own package set. |
170
+ | `amazonlinux` | Adds `--allowerasing` to `dnf install`. |
171
+ | `fedora` | |
172
+ | `arch` | |
173
+ | `gentoo`, `gentoo-paludis` | |
174
+ | `opensuse`, `opensuse/leap`, `opensuse/tumbleweed`, `sles` | |
175
+ | `photon` | |
176
+ | `windows` | Uses Windows containers; see [Windows containers](#windows-containers). |
352
177
 
353
- Adds a tmpfs volume(s) to the suite container.
178
+ Anything else raises `Unknown platform '<name>'`. If your distribution is not
179
+ listed, supply your own [`dockerfile`](#images-and-building) instead.
354
180
 
355
- Examples:
181
+ ## Driver configuration
356
182
 
357
- ```yaml
358
- tmpfs: /tmp
359
- ```
183
+ Everything in this section goes under `driver:` — either at the top level, or
184
+ per-platform and per-suite:
360
185
 
361
186
  ```yaml
362
- tmpfs:
363
- - /tmp:exec
364
- - /run
365
- ```
366
-
367
- ### dns
368
-
369
- Adjusts `resolv.conf` to use the dns servers specified. Otherwise use
370
- Dockers defaults.
371
-
372
- Examples:
187
+ driver:
188
+ name: docker
189
+ privileged: true # applies everywhere
373
190
 
374
- ```yaml
375
- dns: 8.8.8.8
376
- ```
191
+ platforms:
192
+ - name: ubuntu-24.04
193
+ driver:
194
+ forward: # applies to this platform only
195
+ - 8080:80
196
+ ```
197
+
198
+ ### Images and building
199
+
200
+ | Option | Default | Description |
201
+ | --- | --- | --- |
202
+ | `image` | derived from the platform name | Base image for the container. |
203
+ | `platform` | derived from the platform name | Distribution family, used to bootstrap the image. See [above](#choosing-an-image-and-platform). |
204
+ | `dockerfile` | *(none)* | Path to your own Dockerfile, used instead of the generated one. Rendered as [ERB](#using-a-custom-dockerfile). |
205
+ | `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. |
206
+ | `build_options` | *(none)* | Extra flags for `docker build`, as a string or a map. |
207
+ | `build_tempdir` | working directory | Where the generated Dockerfile is written, relative to `build_context`. |
208
+ | `use_cache` | `true` | Use Docker's build cache. `false` adds `--no-cache`. |
209
+ | `remove_images` | `false` | Remove the built image on `kitchen destroy`. |
210
+ | `docker_platform` | *(none)* | Target architecture, passed as `--platform` to both build and run — e.g. `linux/arm64`. |
211
+
212
+ ### Provisioning the image
213
+
214
+ | Option | Default | Description |
215
+ | --- | --- | --- |
216
+ | `provision_command` | *(none)* | Command, or list of commands, to run while building the image. Each becomes a `RUN` line. |
217
+ | `disable_upstart` | `true` | Neutralise upstart on Debian and Ubuntu images that ship a broken copy. Ignored on other platforms. |
218
+ | `username` | `kitchen` on Linux, unset on Windows | Account created in the image and used for the connection. |
219
+ | `private_key` | `.kitchen/docker_id_rsa` | SSH key used to reach the container. Generated on first use if absent. |
220
+ | `public_key` | `.kitchen/docker_id_rsa.pub` | Matching public key, authorised in the image. |
221
+
222
+ ### Running the container
223
+
224
+ | Option | Default | Description |
225
+ | --- | --- | --- |
226
+ | `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. |
227
+ | `run_options` | *(none)* | Extra flags for `docker run`, as a string or a map. |
228
+ | `instance_name` | generated, unique | `--name` for the container. Set it to give other containers a stable name to `link` to. |
229
+ | `hostname` | Docker's default | Container hostname. |
230
+ | `memory` | Docker's default | Memory limit in bytes. |
231
+ | `cpu` | Docker's default | CPU shares (relative weight). |
232
+ | `gpus` | *(none)* | Passed as `--gpus`. Requires a GPU-enabled Docker installation. |
233
+ | `isolation` | Docker's default | Isolation technology — `hyperv` or `process` for Windows containers. |
234
+ | `interactive` | `false` | Pass `-i`, keeping stdin open. |
235
+ | `tty` | `false` | Pass `-t`, allocating a pseudo-TTY. |
236
+ | `env_variables` | *(none)* | Environment variables set in the container, as a map. |
237
+ | `wait_for_transport` | `true` | Wait for the transport to answer before converging. Set `false` for containers that do not stay up. |
238
+ | `detach` | `false` | Run provisioner commands with `docker exec -d`, returning immediately instead of waiting for them. The container itself is always started detached, regardless of this setting, and `kitchen login` ignores it so the shell stays usable. |
239
+
240
+ ### Networking
241
+
242
+ | Option | Default | Description |
243
+ | --- | --- | --- |
244
+ | `forward` | *(none)* | Ports to publish, as `container` or `host:container`. Docker picks the host port if you omit it. |
245
+ | `publish_all` | `false` | Publish every exposed port to a random host port (`-P`). |
246
+ | `dns` | Docker's default | DNS servers for the container. |
247
+ | `add_host` | *(none)* | Extra `/etc/hosts` entries, as a map of hostname to IP. |
248
+ | `links` | *(none)* | Other containers to link, as `name:alias`. |
249
+ | `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. |
250
+
251
+ ### Storage
252
+
253
+ | Option | Default | Description |
254
+ | --- | --- | --- |
255
+ | `volume` | *(none)* | Volumes to add, in `docker run -v` syntax. |
256
+ | `volumes_from` | *(none)* | Containers whose volumes to mount. |
257
+ | `mount` | *(none)* | Mounts in `--mount` syntax. Requires Docker 17.05 or newer. |
258
+ | `tmpfs` | *(none)* | tmpfs mounts, e.g. `/tmp` or `/tmp:exec`. |
259
+ | `devices` | *(none)* | Host devices to share. Must be absolute paths. |
260
+
261
+ Each of these accepts a single value or a list.
262
+
263
+ ### Security and privileges
264
+
265
+ | Option | Default | Description |
266
+ | --- | --- | --- |
267
+ | `privileged` | `false` | Run the container privileged. Needed for systemd, Docker-in-Docker, and some kernel-level tests. |
268
+ | `cap_add` | *(none)* | Capabilities to add, e.g. `SYS_PTRACE`. |
269
+ | `cap_drop` | *(none)* | Capabilities to drop. |
270
+ | `security_opt` | *(none)* | SELinux or AppArmor profiles — finer-grained than `privileged`. |
271
+
272
+ ### Proxies
273
+
274
+ | Option | Default | Description |
275
+ | --- | --- | --- |
276
+ | `http_proxy` | *(none)* | Set as `http_proxy` and `HTTP_PROXY`, both in the image and in the running container. |
277
+ | `https_proxy` | *(none)* | Set as `https_proxy` and `HTTPS_PROXY`, in the image and the container. |
278
+ | `no_proxy` | *(none)* | Set as `no_proxy` and `NO_PROXY` **in the image only**, for use during the build. |
279
+
280
+ ### Connecting to the Docker daemon
281
+
282
+ | Option | Default | Description |
283
+ | --- | --- | --- |
284
+ | `binary` | `docker` | Docker CLI to invoke — e.g. `docker.io`, or an absolute path. |
285
+ | `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. |
286
+ | `use_sudo` | `false` | Run every `docker` command through `sudo`. |
287
+ | `tls` | `false` | Use TLS when connecting. |
288
+ | `tls_verify` | `false` | Verify the daemon's certificate. |
289
+ | `tls_cacert` | *(none)* | Path to the CA certificate. |
290
+ | `tls_cert` | *(none)* | Path to the client certificate. |
291
+ | `tls_key` | *(none)* | Path to the client key. |
292
+
293
+ ## Transport configuration
294
+
295
+ The `docker` transport runs commands with `docker exec` rather than over SSH or
296
+ WinRM. It is the recommended pairing with this driver, and is required for
297
+ Windows containers, which have no WinRM service:
377
298
 
378
299
  ```yaml
379
- dns:
380
- - 8.8.8.8
381
- - 8.8.4.4
300
+ transport:
301
+ name: docker
382
302
  ```
383
303
 
384
- ### http\_proxy
385
-
386
- Sets an http proxy for the suite container using the `http_proxy` environment variable.
304
+ These options go under `transport:`, not `driver:`.
387
305
 
388
- Examples:
306
+ | Option | Default | Description |
307
+ | --- | --- | --- |
308
+ | `binary` | `docker` | Docker CLI to invoke. |
309
+ | `socket` | `$DOCKER_HOST`, else the platform default | Daemon to talk to. |
310
+ | `username` | `kitchen` on Linux, unset on Windows | User that commands run as (`-u`). |
311
+ | `working_dir` | *(none)* | Working directory inside the container (`-w`). |
312
+ | `temp_dir` | `/tmp`, or `$env:TEMP` on Windows | Directory used to stage uploaded files. |
313
+ | `env_variables` | *(none)* | Environment variables for each command. |
314
+ | `privileged` | `false` | Run commands with `--privileged`. |
315
+ | `interactive` | `false` | Pass `-i`. |
316
+ | `tty` | `false` | Pass `-t`. |
317
+ | `tls`, `tls_verify`, `tls_cacert`, `tls_cert`, `tls_key` | as for the driver | TLS settings for the daemon connection. |
389
318
 
390
- ```yaml
391
- http_proxy: http://proxy.host.com:8080
392
- ```
319
+ The driver and transport each read their own copy of `binary`, `socket`,
320
+ `username`, and the TLS settings. If you point one at a non-default daemon,
321
+ point the other at it too.
393
322
 
394
- ### https\_proxy
395
-
396
- Sets an https proxy for the suite container using the `https_proxy` environment variable.
323
+ ## Logging into a container
397
324
 
398
- Examples:
325
+ `kitchen login` opens an interactive shell inside a running container, so you
326
+ do not have to look up the container ID and run `docker exec` yourself:
399
327
 
400
- ```yaml
401
- https_proxy: http://proxy.host.com:8080
328
+ ```sh
329
+ kitchen login default-ubuntu-2404
402
330
  ```
403
331
 
404
- ### forward
332
+ On Linux platforms this starts `/bin/bash --login -i`; on Windows platforms it
333
+ starts `powershell`. The transport's `username`, `working_dir`,
334
+ `env_variables`, and `privileged` settings are honoured, so the shell matches
335
+ the environment the provisioner ran in.
405
336
 
406
- Set suite container port(s) to forward to the host machine. You may specify
407
- the host (public) port in the mappings, if not, Docker chooses for you.
337
+ ## Examples
408
338
 
409
- Examples:
339
+ ### Testing a systemd service
410
340
 
411
- ```yaml
412
- forward: 80
413
- ```
341
+ systemd needs to run as PID 1 with enough privileges to manage cgroups:
414
342
 
415
343
  ```yaml
416
- forward:
417
- - 22:2222
418
- - 80:8080
344
+ platforms:
345
+ - name: almalinux-9
346
+ driver:
347
+ run_command: /usr/sbin/init
348
+ privileged: true
349
+ volume: /sys/fs/cgroup:/sys/fs/cgroup:ro
419
350
  ```
420
351
 
421
- ### hostname
352
+ Because `run_command` is no longer `sshd`, pair this with `transport: docker`
353
+ so Test Kitchen does not try to connect over SSH.
422
354
 
423
- Set the suite container hostname. Otherwise use Dockers default.
355
+ ### Using a custom Dockerfile
424
356
 
425
- Examples:
357
+ Point `dockerfile` at your own file to bypass the generated one entirely:
426
358
 
427
359
  ```yaml
428
- hostname: foobar.local
360
+ platforms:
361
+ - name: custom
362
+ driver:
363
+ dockerfile: test/Dockerfile
364
+ username: dockerfile
365
+ password: dockerfile
429
366
  ```
430
367
 
431
- ### privileged
432
-
433
- Run the suite container in privileged mode. This allows certain functionality
434
- inside the Docker container which is not otherwise permitted.
435
-
436
- The default value is `false`.
437
-
438
- Examples:
368
+ The file is rendered as an **ERB template**, and every driver configuration key
369
+ is available as an instance variable of the same name — `@username`, `@image`,
370
+ `@public_key`, and so on, including keys you invent yourself (`@password`
371
+ above). That is how a custom Dockerfile authorises the key Test Kitchen will
372
+ connect with:
439
373
 
440
- ```yaml
441
- privileged: true
374
+ ```erb
375
+ FROM almalinux:latest
376
+ RUN dnf install -y sudo openssh-server openssh-clients which curl
377
+ RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
378
+ RUN useradd -d /home/<%= @username %> -m -s /bin/bash <%= @username %>
379
+ RUN echo '<%= @username %> ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
380
+ RUN mkdir -p /home/<%= @username %>/.ssh && chmod 0700 /home/<%= @username %>/.ssh
381
+ RUN echo '<%= IO.read(@public_key).strip %>' >> /home/<%= @username %>/.ssh/authorized_keys
442
382
  ```
443
383
 
444
- ### cap\_add
445
-
446
- Adds a capability to the running container.
384
+ A working copy lives in [`test/Dockerfile`](test/Dockerfile). Your Dockerfile
385
+ is responsible for the SSH server and the `authorized_keys` entry — the driver
386
+ adds nothing to it.
447
387
 
448
- Examples:
388
+ ### Building for another architecture
449
389
 
450
390
  ```yaml
451
- cap_add:
452
- - SYS_PTRACE
453
-
391
+ platforms:
392
+ - name: ubuntu-24.04
393
+ driver:
394
+ docker_platform: linux/arm64
454
395
  ```
455
396
 
456
- ### cap\_drop
397
+ This requires emulation — install QEMU binfmt handlers (`docker run --privileged
398
+ --rm tonistiigi/binfmt --install all`) or use a Buildx builder that can reach a
399
+ native node.
457
400
 
458
- Drops a capability from the running container.
459
-
460
- Examples:
401
+ ### Using a remote daemon over TLS
461
402
 
462
403
  ```yaml
463
- cap_drop:
464
- - CHOWN
465
- ```
466
-
467
- ### security\_opt
468
-
469
- Apply a security profile to the Docker container. Allowing finer granularity of
470
- access control than privileged mode, through leveraging SELinux/AppArmor
471
- profiles to grant access to specific resources.
472
-
473
- Examples:
404
+ driver:
405
+ name: docker
406
+ socket: tcp://docker.example.com:2376
407
+ tls: true
408
+ tls_verify: true
409
+ tls_cacert: ~/.docker/ca.pem
410
+ tls_cert: ~/.docker/cert.pem
411
+ tls_key: ~/.docker/key.pem
474
412
 
475
- ```yaml
476
- security_opt:
477
- - apparmor:my_profile
413
+ transport:
414
+ name: docker
415
+ socket: tcp://docker.example.com:2376
416
+ tls: true
417
+ tls_verify: true
418
+ tls_cacert: ~/.docker/ca.pem
419
+ tls_cert: ~/.docker/cert.pem
420
+ tls_key: ~/.docker/key.pem
478
421
  ```
479
422
 
480
- ### dockerfile
423
+ `build_context` defaults to `false` against a remote daemon, since sending the
424
+ whole working directory over the network is slow. Set it to `true` if your
425
+ Dockerfile uses `ADD` or `COPY`.
481
426
 
482
- Use a custom Dockerfile, instead of having Kitchen-Docker build one for you.
483
-
484
- Examples:
427
+ ### Windows containers
485
428
 
486
429
  ```yaml
487
- dockerfile: test/Dockerfile
488
- ```
489
-
490
- ### instance\_name
491
-
492
- Set the name of container to link to other container(s).
430
+ driver:
431
+ name: docker
493
432
 
494
- Examples:
433
+ transport:
434
+ name: docker
435
+ socket: tcp://localhost:2375
495
436
 
496
- ```yaml
497
- instance_name: web
437
+ platforms:
438
+ - name: windows-2022
439
+ driver:
440
+ image: mcr.microsoft.com/windows/servercore:ltsc2022
441
+ platform: windows
442
+ isolation: hyperv
498
443
  ```
499
444
 
500
- ### links
501
-
502
- Set ```instance_name```(and alias) of other container(s) that connect from the suite container.
503
-
504
- Examples:
505
-
506
- ```yaml
507
- links: db:db
508
- ```
445
+ Windows containers have no WinRM service, so `transport: docker` is required
446
+ rather than optional. If you use the InSpec verifier on Windows, the named-pipe
447
+ socket will not work the daemon must listen on TCP. Add `hosts` to
448
+ `C:\ProgramData\docker\config\daemon.json`:
509
449
 
510
- ```yaml
511
- links:
512
- - db:db
513
- - kvs:kvs
450
+ ```json
451
+ {
452
+ "hosts": ["tcp://0.0.0.0:2375"]
453
+ }
514
454
  ```
515
455
 
516
- ### publish\_all
517
-
518
- Publish all exposed ports to the host interfaces.
519
- This option used to communicate between some containers.
520
-
521
- The default value is `false`.
522
-
523
- Examples:
456
+ ### Building behind a proxy
524
457
 
525
458
  ```yaml
526
- publish_all: true
459
+ driver:
460
+ name: docker
461
+ http_proxy: http://proxy.example.com:8080
462
+ https_proxy: http://proxy.example.com:8080
463
+ no_proxy: localhost,127.0.0.1,.internal.example.com
527
464
  ```
528
465
 
529
- ### devices
530
-
531
- Share a host device with the container. Host device must be an absolute path.
466
+ ### Linking containers together
532
467
 
533
- Examples:
468
+ Give the container a stable name, then link to it from another suite:
534
469
 
535
470
  ```yaml
536
- devices: /dev/vboxdrv
537
- ```
471
+ suites:
472
+ - name: database
473
+ driver:
474
+ instance_name: db
538
475
 
539
- ```yaml
540
- devices:
541
- - /dev/vboxdrv
542
- - /dev/vboxnetctl
476
+ - name: web
477
+ driver:
478
+ links:
479
+ - db:db
543
480
  ```
544
481
 
545
- ### build_context
546
-
547
- Transfer the cookbook directory (cwd) as build context. This is required for
548
- Dockerfile commands like ADD and COPY. When using a remote Docker server, the
549
- whole directory has to be copied, which can be slow.
482
+ ### Running Test Kitchen inside a container
550
483
 
551
- The default value is `true` for local Docker and `false` for remote Docker.
552
-
553
- Examples:
484
+ When Test Kitchen itself runs in a container, forwarded host ports are not
485
+ reachable. Connect over the Docker network instead:
554
486
 
555
487
  ```yaml
556
- build_context: true
488
+ driver:
489
+ name: docker
490
+ use_internal_docker_network: true
557
491
  ```
558
492
 
559
- ### build_options
493
+ ### Passing flags the driver has no option for
560
494
 
561
- Extra command-line options to pass to `docker build` when creating the image.
562
-
563
- Examples:
564
-
565
- ```yaml
566
- build_options: --rm=false
567
- ```
495
+ `build_options` and `run_options` are escape hatches, accepting either a raw
496
+ string or a map that is expanded into flags:
568
497
 
569
498
  ```yaml
499
+ driver:
570
500
  build_options:
571
501
  rm: false
572
- build-arg: something
573
- ```
574
-
575
- ### run_options
576
-
577
- Extra command-line options to pass to `docker run` when starting the container.
578
-
579
- Examples:
580
-
581
- ```yaml
502
+ build-arg: VERSION=1.2.3
582
503
  run_options: --ip=1.2.3.4
583
504
  ```
584
505
 
585
- ```yaml
586
- run_options:
587
- tmpfs:
588
- - /run/lock
589
- - /tmp
590
- net: br3
591
- ```
592
-
593
- ### build_tempdir
594
-
595
- Relative (to `build_context`) temporary directory path for built Dockerfile.
506
+ ## Using with Chef
596
507
 
597
- Example:
508
+ This driver is not tied to Cinc. It builds images and runs containers; it does
509
+ not install either distribution — that is the provisioner's job. If you use
510
+ [Chef Workstation][chef_workstation] rather than
511
+ [Cinc Workstation][cinc_workstation], use `chef_infra` and `inspec`:
598
512
 
599
513
  ```yaml
600
- build_tempdir: .kitchen
601
- ```
602
-
603
- ### use_internal_docker_network
604
-
605
- If you want to use kitchen-docker from within another Docker container you'll
606
- need to set this to true. When set to true uses port 22 as the SSH port and
607
- the IP of the container that chef is going to run in as the hostname so that
608
- you can connect to it over SSH from within another Docker container.
514
+ provisioner:
515
+ name: chef_infra
609
516
 
610
- Examples:
611
-
612
- ```yaml
613
- use_internal_docker_network: true
517
+ verifier:
518
+ name: inspec
614
519
  ```
615
520
 
616
- ### docker_platform
521
+ No driver configuration changes are needed.
617
522
 
618
- Configure the CPU platform (architecture) used by docker to build the image.
523
+ ## Troubleshooting
619
524
 
620
- Examples:
525
+ **The container exits immediately.** `run_command` must stay in the
526
+ foreground. A command that forks and returns leaves the container with nothing
527
+ running, and Docker stops it.
621
528
 
622
- ```yaml
623
- docker_platform: linux/arm64
624
- ```
529
+ **`Unknown platform '<name>'`.** The `platform` value is not one the driver can
530
+ bootstrap. Set it to a supported family, or supply your own
531
+ [`dockerfile`](#using-a-custom-dockerfile).
625
532
 
626
- ```yaml
627
- docker_platform: linux/amd64
628
- ```
533
+ **`ADD` or `COPY` cannot find a file.** Set `build_context: true`. It defaults
534
+ to `false` against a remote daemon.
629
535
 
630
- ## Logging into a container
536
+ **Permission denied talking to the daemon.** Either add your user to the
537
+ `docker` group, or set `use_sudo: true`.
631
538
 
632
- `kitchen login` opens an interactive shell inside a running container using the
633
- Docker transport, so you do not need to look up the container ID and run
634
- `docker exec` by hand:
539
+ **Anything else.** Run with `-l debug`:
635
540
 
636
- ```bash
637
- kitchen login default-ubuntu-2404
541
+ ```sh
542
+ kitchen converge default-ubuntu-2404 -l debug
638
543
  ```
639
544
 
640
- The session runs `docker exec` against the instance's container. On Linux
641
- platforms it starts `/bin/bash --login -i`; on Windows platforms it starts
642
- `powershell`. The transport's `username`, `working_dir`, `env_variables` and
643
- `privileged` settings are honoured, so the shell matches the environment that
644
- Test Kitchen uses when it runs the provisioner.
545
+ The debug log contains the generated Dockerfile and the exact `docker build`
546
+ and `docker run` command lines, which is usually enough to see what went wrong.
645
547
 
646
- ## Development
548
+ ## Contributing
647
549
 
648
- * Source hosted at [GitHub][repo]
649
- * Report issues/questions/feature requests on [GitHub Issues][issues]
550
+ Bug reports and pull requests are welcome on [GitHub][repo]; please report
551
+ issues on [GitHub Issues][issues].
650
552
 
651
- Pull requests are very welcome! Make sure your patches are well tested.
652
- Ideally create a topic branch for every separate change you make. For
653
- example:
654
-
655
- 1. Fork the repo
656
- 2. Create your feature branch (`git checkout -b my-new-feature`)
657
- 3. Commit your changes (`git commit -am 'Added some feature'`)
658
- 4. Push to the branch (`git push origin my-new-feature`)
659
- 5. Create new Pull Request
553
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, how to run the
554
+ unit and integration tests, and the release process.
660
555
 
661
556
  ## License
662
557
 
663
- ```text
664
558
  Copyright 2013-2016, [Sean Porter](https://github.com/portertech)
665
559
  Copyright 2015-2016, [Noah Kantrowitz](https://github.com/coderanger)
666
560
 
667
- Licensed under the Apache License, Version 2.0 (the "License");
668
- you may not use this file except in compliance with the License.
669
- You may obtain a copy of the License at
670
-
671
- http://www.apache.org/licenses/LICENSE-2.0
672
-
673
- Unless required by applicable law or agreed to in writing, software
674
- distributed under the License is distributed on an "AS IS" BASIS,
675
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
676
- See the License for the specific language governing permissions and
677
- limitations under the License.
678
- ```
679
-
680
- [issues]: https://github.com/test-kitchen/kitchen-docker/issues
681
- [repo]: https://github.com/test-kitchen/kitchen-docker
682
- [docker_installation]: https://docs.docker.com/installation/#installation
683
- [docker_index]: https://index.docker.io/
684
- [test_kitchen_docs]: https://kitchen.ci/docs/getting-started/introduction/
685
- [chef_omnibus_dl]: https://downloads.chef.io/tools/infra-client
686
- [cpu_shares]: https://docs.fedoraproject.org/en-US/Fedora/17/html/Resource_Management_Guide/sec-cpu.html
687
- [memory_limit]: https://docs.fedoraproject.org/en-US/Fedora/17/html/Resource_Management_Guide/sec-memory.html
561
+ Licensed under the Apache License, Version 2.0. You may obtain a copy of the
562
+ License at <https://www.apache.org/licenses/LICENSE-2.0>. See
563
+ [LICENSE](LICENSE) for the full text.
564
+
565
+ [issues]: https://github.com/test-kitchen/kitchen-docker/issues
566
+ [repo]: https://github.com/test-kitchen/kitchen-docker
567
+ [dokken]: https://github.com/test-kitchen/kitchen-dokken
568
+ [docker_installation]: https://docs.docker.com/engine/install/
569
+ [test_kitchen_docs]: https://kitchen.ci/docs/getting-started/introduction/
570
+ [cinc_workstation]: https://cinc.sh/start/workstation/
571
+ [chef_workstation]: https://www.chef.io/downloads/tools/workstation