Skip to content

feat(container): add Container.with_name/2#255

Merged
jarlah merged 1 commit into
mainfrom
fix/177-container-name
Apr 22, 2026
Merged

feat(container): add Container.with_name/2#255
jarlah merged 1 commit into
mainfrom
fix/177-container-name

Conversation

@jarlah
Copy link
Copy Markdown
Member

@jarlah jarlah commented Apr 22, 2026

Summary

  • Add a name field (default nil) to the Testcontainers.Container struct and a with_name/2 builder styled like the other with_* helpers.
  • Wire container.name into Docker.Api.create_container/2 so it is passed as the name query parameter to Docker's /containers/create endpoint.
  • Lets users assign a stable, known name to a container (equivalent to docker run --name foo) so other containers on the same network can reference it by name.

Test plan

  • mix compile (no new warnings)
  • mix credo --strict (no issues)
  • mix dialyzer (0 errors)
  • mix test test/container_test.exs — unit tests cover default nil, setting a name, and overwriting a previously set name
  • mix test test/testcontainers_test.exs — integration test starts a container with a custom name and asserts Docker assigned it (/<name>)

Fixes #177

Adds a `name` field (default nil) to the `Testcontainers.Container`
struct and a `with_name/2` builder that assigns a custom name to the
container at creation time, wired through to Docker's
`/containers/create` `name` query parameter.

This lets users give a container a stable, well-known name (like
`docker run --name foo`) so other containers on the same network can
reference it by that name.

Fixes #177
@jarlah jarlah merged commit 9915b48 into main Apr 22, 2026
8 checks passed
@jarlah jarlah deleted the fix/177-container-name branch April 22, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Being able to set/get the container name like docker

1 participant