Configuration¶
Container runtime access¶
Testcontainers for PHP talks to a Docker-compatible runtime through one of two exchangeable adapters:
| Adapter | TESTCONTAINERS_CLIENT |
How it works | Use when |
|---|---|---|---|
| API (default) | api |
Docker Engine HTTP API over the socket or TCP endpoint from DOCKER_HOST |
Docker Desktop, Docker Engine, OrbStack, Colima, Podman with its API service enabled |
| CLI | cli |
Runs a Docker-compatible binary (docker, podman, nerdctl, ...) as a subprocess |
The daemon socket is not reachable from PHP, e.g. rootless Podman without podman system service, remote Docker contexts, or SSH-based setups |
Both adapters implement Testcontainers\Docker\DockerClientInterface, so containers, modules and wait strategies behave the same regardless of the adapter.
Using Podman¶
Podman ships a Docker-compatible API socket. Either point the default adapter at it:
1 2 | |
or skip the socket entirely and drive the podman binary:
1 2 | |
Selecting an adapter in code¶
The adapter can also be set programmatically before the first container is started:
1 2 3 4 | |
Any class implementing DockerClientInterface can be injected this way, which allows custom adapters.
Environment variables¶
TESTCONTAINERS_CLIENT¶
Selects the runtime adapter: api (default) or cli.
1 | |
TESTCONTAINERS_CLI_BINARY¶
Binary used by the cli adapter. Defaults to docker. The subprocess inherits your environment, so DOCKER_CONTEXT, DOCKER_HOST or Podman's CONTAINER_HOST apply as usual.
1 | |
DOCKER_HOST¶
Defines where the Docker API is available for the api adapter.
Examples:
1 2 | |
TESTCONTAINERS_HOST_OVERRIDE¶
Overrides the host address returned by Testcontainers when your tests need a custom endpoint:
1 | |
Running inside containers¶
If your tests run inside another container:
- Mount the Docker socket.
- Ensure network routing from test container to started containers is valid.
- Set host overrides when needed for your CI/network topology.
For startup and connectivity failures, see troubleshooting.