Low-level container control operations via the Docker Engine API.
These functions talk directly to the Docker Engine API and work with
raw container IDs. They are useful for fine-grained control beyond
what the high-level TestcontainerEx API provides.
All functions accept an optional base_url parameter. When omitted,
the URL is derived from CONTAINER_ENGINE_HOST (or DOCKER_HOST as fallback),
or defaults to http://d.
Usage
# Pause a container
:ok = TestcontainerEx.Docker.Control.pause("abc123")
# Get live resource stats
stats = TestcontainerEx.Docker.Control.stats("abc123")
# Upload a file
:ok = TestcontainerEx.Docker.Control.upload("abc123", "/app/config.yml", "config.yml")
# Download a file
{:ok, data} = TestcontainerEx.Docker.Control.download("abc123", "/app/data.json")
# Commit container to a new image
{:ok, image_id} = TestcontainerEx.Docker.Control.commit("abc123", "my-snapshot:v1")
Summary
Functions
Attaches to a container's streams.
Commits a container to a new image.
Creates a container from a config map. Returns {:ok, container_id}.
Creates an exec instance inside a container.
Creates a container with a specific name.
Downloads a file from a container as binary data.
Downloads and extracts a single file from a container archive.
Exports a container filesystem as a tarball.
Returns detailed container inspection.
Inspects an exec instance.
Kills a running container with the given signal (default: SIGKILL).
Fetches container logs.
Pauses a running container.
Removes a container. Options: :force, :remove_volumes.
Renames a container.
Resizes a container TTY.
Resizes an exec TTY.
Restarts a running container. Optional t parameter for timeout in seconds.
Returns whether the container is running.
Starts a stopped container.
Starts a previously created exec instance.
Returns container state (running, paused, etc.).
Returns live resource usage statistics.
Stops a running container. Optional t parameter for timeout in seconds.
Returns running processes inside the container.
Unpauses a paused container.
Updates container resources (memory, CPU, etc.).
Uploads a file to a container.
Waits for a container to finish and returns its exit code.
Functions
@spec attach(String.t(), keyword(), String.t() | nil) :: {:ok, binary() | reference()} | {:error, term()}
Attaches to a container's streams.
Returns {:ok, reference()} for streaming mode.
@spec commit(String.t(), String.t(), keyword(), String.t() | nil) :: {:ok, String.t()} | {:error, term()}
Commits a container to a new image.
Creates a container from a config map. Returns {:ok, container_id}.
@spec create_exec(String.t(), [String.t()], keyword(), String.t() | nil) :: {:ok, String.t()} | {:error, term()}
Creates an exec instance inside a container.
Creates a container with a specific name.
Downloads a file from a container as binary data.
Downloads and extracts a single file from a container archive.
Exports a container filesystem as a tarball.
Returns detailed container inspection.
Inspects an exec instance.
Kills a running container with the given signal (default: SIGKILL).
Fetches container logs.
Options:
:stdout— include stdout (default: true):stderr— include stderr (default: true):timestamps— include timestamps (default: false):follow— stream logs (default: false):tail— number of lines from end (default: "all"):since— UNIX timestamp for logs since:until— UNIX timestamp for logs until
Pauses a running container.
Removes a container. Options: :force, :remove_volumes.
Renames a container.
Resizes a container TTY.
Resizes an exec TTY.
Restarts a running container. Optional t parameter for timeout in seconds.
Returns whether the container is running.
Starts a stopped container.
Starts a previously created exec instance.
Returns container state (running, paused, etc.).
Returns live resource usage statistics.
Options:
:stream— stream stats (default: true)
Stops a running container. Optional t parameter for timeout in seconds.
Returns running processes inside the container.
Unpauses a paused container.
Updates container resources (memory, CPU, etc.).
@spec upload(String.t(), String.t(), String.t() | binary(), String.t() | nil) :: :ok | {:error, term()}
Uploads a file to a container.
The source can be:
- A file path (string) — the file is read and uploaded
- A binary — uploaded directly as the file contents
Waits for a container to finish and returns its exit code.