Skip to content

Conversation

kevinalh
Copy link

@kevinalh kevinalh commented Oct 2, 2025

The Docker container create command supports the --hostname parameter (1). This is also supported through the Bollard library as part of the the ContainerCreateBody struct (2). This commit adds the option to configure this parameter through the ImageExt trait.

This was previously proposed for an older version of testcontainers-rs (3), however it was rejected.

The usefulness of this feature is to allow programs inside the container to report back a hostname that makes sense in a test environment. For instance, ClickHouse has the hostName function (4) which will report this configured value. By default Docker assigns the Docker container ID, which in an integration testing context isn't that useful.

The Docker container create command supports the --hostname parameter
[1]. This is also supported through the Bollard library as part of the
the ContainerCreateBody struct [2]. This commit adds the option to
configure this parameter through the ImageExt trait.

This was previously proposed for an older version of testcontainers-rs
[3], however it was rejected.

The usefulness of this feature is to allow programs inside the container
to report back a hostname that makes sense in a test environment. For
instance, ClickHouse has the hostName function [4] which will report
this configured value. By default Docker assigns the Docker container
ID, which in an integration testing context isn't that useful.

[1]: https://docs.docker.com/reference/cli/docker/container/create/
[2]: https://docs.rs/bollard/latest/bollard/secret/struct.ContainerCreateBody.html
[3]: testcontainers#539
[4]: https://clickhouse.com/docs/sql-reference/functions/other-functions#hostname

Signed-off-by: Kevin Languasco <[email protected]>
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for testcontainers-rust ready!

Name Link
🔨 Latest commit 45fb073
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-rust/deploys/68de6f7284522d0007e819c0
😎 Deploy Preview https://deploy-preview-848--testcontainers-rust.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

@arturocuya arturocuya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mucho chatgpt

Copy link
Contributor

@DDtKey DDtKey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me and I definitely can imagine plenty of use cases for this for integration testing scenarios

Thanks for the contribution! 🙏

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.

3 participants