Docker.Stream (docker_wrapper v0.1.2)

Copy Markdown View Source

Port-based streaming for long-running Docker commands.

A BEAM-native extension not present in the Rust crate. Useful for docker logs --follow, docker events, docker build, etc.

Lines are sent as messages to the subscriber process:

{:docker_stream, pid, {:stdout, line}}
{:docker_stream, pid, {:exit, exit_code}}

Examples

# Stream logs from a container
{:ok, stream} = Docker.Stream.start_link(
  Docker.Commands.Logs.new("my-container") |> Docker.Commands.Logs.follow(),
  subscriber: self()
)

receive do
  {:docker_stream, ^stream, {:stdout, line}} ->
    IO.puts("LOG: #{line}")
  {:docker_stream, ^stream, {:exit, 0}} ->
    IO.puts("Stream ended")
end

# Stop streaming
Docker.Stream.stop(stream)

Options

  • :subscriber - PID to receive stream messages (required)
  • :config - Docker.Config to use (default: Docker.Config.new())

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts a streaming process for the given command.

Stops the streaming process.

Types

stream_message()

@type stream_message() ::
  {:docker_stream, pid(), {:stdout, String.t()}}
  | {:docker_stream, pid(), {:exit, non_neg_integer()}}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(cmd, opts)

@spec start_link(struct(), keyword()) :: GenServer.on_start()

Starts a streaming process for the given command.

stop(pid)

@spec stop(GenServer.server()) :: :ok

Stops the streaming process.