Container configuration struct and builder functions.
This module is pure data — no side effects, no Docker API calls.
Use TestcontainerEx.Container.Builder for protocol-based build pipelines.
Summary
Functions
Formats a list of exposed ports into a human-readable string.
Returns true when running inside a container (Docker, Podman, Kubernetes).
Sets the log consumer level for streaming container logs to Logger.
Sets a correlation / request ID for tracing this container start.
Types
@type t() :: %TestcontainerEx.Container.Config{ auth: String.t() | nil, auto_remove: boolean(), bind_mounts: [map()], bind_volumes: [map()], check_image: Regex.t() | nil, cmd: [String.t()] | nil, container_id: String.t() | nil, copy_to: [map()], dns: [String.t()], domainname: String.t() | nil, environment: %{required(atom() | String.t()) => String.t()}, exposed_ports: [{integer(), integer() | nil}], extra_hosts: [{String.t(), String.t()}], force_reuse: boolean(), hostname: String.t() | nil, image: String.t(), ip_address: String.t() | nil, labels: %{required(String.t()) => String.t()}, log_consumer: Logger.level() | nil, memory: integer() | nil, name: String.t() | nil, nano_cpus: integer() | nil, network: String.t() | nil, network_mode: String.t() | nil, privileged: boolean(), pull_policy: TestcontainerEx.PullPolicy.t() | nil, request_id: String.t() | nil, restart_policy: String.t() | nil, reuse: boolean(), stop_signal: String.t() | nil, stop_timeout: integer() | nil, user: String.t() | nil, wait_strategies: [struct()], working_dir: String.t() | nil }
Container configuration.
Fields:
:image— Docker image reference (e.g."postgres:15-alpine").:cmd— override the image's default command.:environment— map of environment variables.:auth— optional Base64-encoded auth token for private registries.:exposed_ports— list of{container_port, host_port | nil}tuples.:ip_address— resolved IP address of the running container.:wait_strategies— list of strategies determining when the container is ready.:privileged— run the container in privileged mode.:bind_mounts— list of bind mount specifications.:bind_volumes— list of named volume mount specifications.:copy_to— list of files to copy into the container at startup.:labels— map of Docker labels to attach to the container.:auto_remove— automatically remove the container when it stops.:container_id— ID of the running container (set after start).:check_image— optional regex to validate the image name.:network_mode— Docker network mode (e.g."host","bridge").:network— network name to connect the container to.:hostname— container hostname.:name— optional stable container name.:reuse— whentrue, an existing container with the same config may be reused.:force_reuse— force reuse even if the container is stale.:pull_policy— controls when the image is pulled; seeTestcontainerEx.PullPolicy.:log_consumer— optional Logger level to stream container logs to (:debug,:info, etc.).:request_id— correlation ID for tracing astart_containercall.:memory— memory limit in bytes (DockerHostConfig.Memory).:nano_cpus— CPU limit in nano CPUs (DockerHostConfig.NanoCpus).:restart_policy— restart policy name (e.g."always","on-failure:5").:dns— list of DNS servers (DockerHostConfig.Dns).:extra_hosts— list of{hostname, ip}extra host entries (DockerHostConfig.ExtraHosts).:user— user (UID oruser:group) to run the container as (DockerUser).:working_dir— working directory inside the container (DockerWorkingDir).:stop_signal— stop signal sent to the container (DockerStopSignal).:stop_timeout— stop timeout in seconds (DockerHostConfig.StopTimeout).:domainname— DNS domain name for the container (DockerDomainname).
Functions
Formats a list of exposed ports into a human-readable string.
Examples
iex> format_ports([{8080, 32768}, {9090, nil}])
"8080->32768, 9090->auto"
@spec os_type() :: :linux | :macos | :windows | :unknown
Returns true when running inside a container (Docker, Podman, Kubernetes).
Accepts optional overrides for the .dockerenv path, cgroup path,
Kubernetes secrets path, and Podman containerenv path.
@spec valid_image(t()) :: {:ok, t()} | {:error, TestcontainerEx.Error.t()}
@spec with_log_consumer(t(), Logger.level()) :: t()
Sets the log consumer level for streaming container logs to Logger.
When set, container stdout/stderr will be piped through Logger at the
specified level after the container starts.
@spec with_memory_limit(t(), pos_integer()) :: t()
Sets a correlation / request ID for tracing this container start.
If not set, one will be generated automatically by start_container/1.
@spec with_stop_timeout(t(), non_neg_integer()) :: t()