testcontainers / testcontainers/testcontainers-dotnet

[Enhancement]: Expose configuration of ExposeHostPortsAsync container `PortForwardingContainer`

Open
#1,331 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement module
Dominant language
C#
Stars
4.4k
Forks
357
Avg merge
14h 42m
Merged PRs (30d)
16

Description

Problem

I want to configure PortForwardingContainer so that I can add custom logger to the TestContainer that is used by ExposeHostPortsAsync.

Current code:

await TestcontainersSettings.ExposeHostPortsAsync(3050);

Expected code:

await PortForwardingSettings.Configure(builder =>
        {
            var logger = GetLogger<PortForwardingContainer>();
            return builder
                .WithLogger(logger);
        }).ExposeHostPortsAsync(3050);
Solution

Proposed solutions:

  1. Expose PortForwardingContainer from internal to public so that configuration can be made on a instance, and split Instance from Build so that builder can be preconfigured
  2. Expose OptionsBuilder via ExposeHostPortsAsync
  3. Add new endpoint that allows for ConfigureExposeHostPorts
Benefit

I can redirect all the logs and monitor what is happening via logger of my choice

Alternatives

I tried to copy PortForwardingContainer and all necessary classes from the source repository and use them with configuration instead of TestcontainersSettings.ExposeHostPortsAsync but it doesn't seem to be working.

sshd image is created, but /etc/hosts is not modified and there is lack of documentation or code reference on why is that. The only part I changed is to expose the builder part of the container.

Would you like to help contributing this enhancement?

Yes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing TestcontainersSettings.ExposeHostPortsAsync and the internal PortForwardingContainer path. Compare the three proposed configuration approaches and inspect the existing builder usage described in the issue. Done means callers can configure a custom logger while host-port exposure still updates /etc/hosts correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, docker
Domain
devtools, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.