TestcontainerEx.Compose.Cli (testcontainer_ex v0.1.0)

Copy Markdown View Source

Subprocess wrapper for Docker Compose CLI interaction.

Supports both Docker and Podman compose providers. The compose command is auto-detected in the following order:

  1. CONTAINER_COMPOSE_PROVIDER / PODMAN_COMPOSE_PROVIDER env var
  2. podman compose (podman 4+ built-in)
  3. docker (default fallback)

Summary

Functions

Builds the argument list for docker compose down.

Builds the argument list for docker compose logs.

Builds the argument list for docker compose ps.

Builds the argument list for docker compose pull.

Builds the argument list for docker compose up.

Returns the compose command binary to use.

Runs docker compose down with the given compose configuration.

Runs docker compose logs <service> and returns the output.

Parses the JSON output from docker compose ps.

Parses the Publishers field from a docker compose ps JSON entry into a list of {container_port, host_port} tuples.

Runs docker compose ps --format=json and parses the output into a list of maps.

Runs docker compose pull with the given compose configuration.

Runs docker compose up -d --wait with the given compose configuration.

Functions

build_down_args(compose)

Builds the argument list for docker compose down.

build_logs_args(compose, service_name)

Builds the argument list for docker compose logs.

build_ps_args(compose)

Builds the argument list for docker compose ps.

build_pull_args(compose)

Builds the argument list for docker compose pull.

build_up_args(compose)

Builds the argument list for docker compose up.

compose_command()

Returns the compose command binary to use.

Auto-detects the available compose provider with the following precedence:

  1. The CONTAINER_COMPOSE_PROVIDER or PODMAN_COMPOSE_PROVIDER environment variable.
  2. podman if it supports the compose subcommand (podman 4+).
  3. docker as the default fallback.

The result is cached after the first call.

down(compose)

Runs docker compose down with the given compose configuration.

logs(compose, service_name)

Runs docker compose logs <service> and returns the output.

parse_ps_output(output)

Parses the JSON output from docker compose ps.

Each line is a separate JSON object with fields like Service, ID, State, Publishers.

parse_publishers(publishers)

Parses the Publishers field from a docker compose ps JSON entry into a list of {container_port, host_port} tuples.

ps(compose)

Runs docker compose ps --format=json and parses the output into a list of maps.

pull(compose)

Runs docker compose pull with the given compose configuration.

up(compose)

Runs docker compose up -d --wait with the given compose configuration.