Skip to content

Commit f001b8f

Browse files
committed
docs(readme): document pull policy, naming, registry auth, TLS, Ryuk privileged
Adds a Configuration section covering recent functionality: - Pull policy (default pull_if_missing, always/never/conditional) - Naming containers via Container.with_name/2 - Automatic registry credential resolution from ~/.docker/config.json - TLS-secured Docker hosts via DOCKER_HOST + DOCKER_CERT_PATH - Running Ryuk privileged for SELinux / rootless environments
1 parent 86fff90 commit f001b8f

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [Prerequisites](#prerequisites)
99
- [Installation](#installation)
1010
- [Usage](#usage)
11+
- [Configuration](#configuration)
1112
- [API Documentation](#api-documentation)
1213
- [Contributing](#contributing)
1314
- [License](#license)
@@ -199,6 +200,78 @@ While the old task will continue to work, we recommend updating to `mix testcont
199200

200201
Testcontainers use the standard Logger, see https://hexdocs.pm/logger/Logger.html.
201202

203+
## Configuration
204+
205+
### Pull policy
206+
207+
By default, Testcontainers pulls an image only when it isn't already present in the local Docker daemon. This avoids Docker Hub rate limits on repeated test runs. The policy per container can be overridden:
208+
209+
```elixir
210+
alias Testcontainers.{Container, PullPolicy}
211+
212+
# pulled only if not present locally (default)
213+
%Container{image: "redis:7", pull_policy: PullPolicy.pull_if_missing()}
214+
215+
# always pull, bypassing any cached image
216+
%Container{image: "redis:7", pull_policy: PullPolicy.always_pull()}
217+
218+
# never pull; expect the image to exist locally
219+
%Container{image: "redis:7", pull_policy: PullPolicy.never_pull()}
220+
221+
# conditional pull; pass a 2-arity function
222+
%Container{
223+
image: "redis:7",
224+
pull_policy: PullPolicy.pull_condition(fn _config, _conn -> should_pull?() end)
225+
}
226+
```
227+
228+
The global default can also be set in `~/.testcontainers.properties` via `pull.policy` (`missing` — default, `always`, or `never`).
229+
230+
### Naming containers
231+
232+
Give a container a stable name so other containers on the same network can reference it by name:
233+
234+
```elixir
235+
Testcontainers.Container.new("postgres:16")
236+
|> Testcontainers.Container.with_name("my-postgres")
237+
```
238+
239+
The name is passed straight through to Docker's `/containers/create` as the `name` query parameter, so the usual Docker rules apply (must be unique on the daemon, `[a-zA-Z0-9][a-zA-Z0-9_.-]+`).
240+
241+
### Private registries
242+
243+
If the image lives on a registry that requires authentication, Testcontainers automatically resolves credentials from the user's Docker config on image pull. The lookup order is:
244+
245+
1. `Container.auth` if set explicitly — always wins.
246+
2. The `auths` map in `$DOCKER_CONFIG/config.json` (or `~/.docker/config.json` if `DOCKER_CONFIG` is unset). The registry host of the image is matched against entries in the map.
247+
3. Anonymous pull.
248+
249+
Only the `auths` map is consulted; credential-helper binaries (`credsStore`, `credHelpers`) are not invoked. If an auto-resolved credential is rejected with a 4xx, the pull is retried once anonymously to keep stale entries in `config.json` from breaking pulls that would otherwise succeed without auth.
250+
251+
To log in before running tests:
252+
253+
```bash
254+
docker login myregistry.example.com
255+
```
256+
257+
### TLS-secured Docker hosts
258+
259+
Testcontainers recognizes TLS-secured Docker daemons out of the box. Point it at one with:
260+
261+
- `DOCKER_HOST=https://docker.example.internal:2376`, or
262+
- `DOCKER_HOST=tcp://docker.example.internal:2376` plus `DOCKER_TLS_VERIFY=1`.
263+
264+
The client looks for `ca.pem`, `cert.pem`, and `key.pem` in the directory named by `DOCKER_CERT_PATH` (or `~/.docker` if unset); whichever files are present are used to build the SSL context, matching the Docker CLI's behavior. When `DOCKER_TLS_VERIFY` is unset, peer verification is disabled and a warning is logged.
265+
266+
### Ryuk under SELinux / rootless Docker
267+
268+
On distributions that enforce SELinux (for example Fedora), the Ryuk reaper container may be denied write access to the Docker socket unless it runs privileged. Enable it with either:
269+
270+
- the `ryuk.container.privileged=true` property in `~/.testcontainers.properties`, or
271+
- the `TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED=true` environment variable (takes precedence over the property).
272+
273+
Ryuk only runs privileged when one of these is set to `true` or `1`.
274+
202275
## API Documentation
203276

204277
For more detailed information about the API, different container configurations, and advanced usage scenarios, please refer to the [API documentation](https://hexdocs.pm/testcontainers/api-reference.html).

0 commit comments

Comments
 (0)