Pago, the paguro mascot, carrying a Docker container on his shell

testcontainer

Hex Package Hex Docs CI License: MIT Made with Gleam

The hermit-crab way to run Docker containers in your Gleam tests. Meet Pago, your paguro mascot. He carries the container so you don't have to.

A small, type-safe Gleam library for spinning up real Docker containers from your tests and dev tooling. Start a Postgres, run a query, shut it down. Typed lifecycle and automatic cleanup even if your test process crashes (except abrupt VM termination, e.g. kill -9).

use redis <- testcontainer.with_container(
  container.new("redis:7-alpine")
  |> container.expose_port(port.tcp(6379))
  |> container.wait_for(wait.log("Ready to accept connections")),
)
let assert Ok(host_port) = container.host_port(redis, port.tcp(6379))
// connect to 127.0.0.1:host_port

Why use it

Install

gleam add testcontainer

Upgrading to 1.1

Standalone formula acquire and release callbacks now run in the same dedicated guard process so cleanup can continue if the caller is killed. The body still runs in the caller. If your callbacks depend on process-local state or return resources restricted to the acquiring process, adapt them before upgrading. See Standalone resource lifecycles and the changelog.

Documentation

Full API docs: https://hexdocs.pm/testcontainer

License

MIT.