Skip to content

[Feature Request] Expose published host ports of a container #196

@pdevito3

Description

@pdevito3

Hey there, huge fan of the library! Very well done.

Wondering if it would be possible to expose the host ports for a container? I'm able to get the exposed ports, but not the host ones.

For example, if i did this:

var container = new Builder().UseContainer()
                    .WithName("MyName")
                    .UseImage($"{DB_IMAGE}:{DB_IMAGE_TAG}")
                    .ExposePort(freePort, 5432)
                    .WithEnvironment(
                        "POSTGRES_PASSWORD={DB_PASSWORD}",
                        $"POSTGRES_DB={DB_NAME}",
                        $"POSTGRES_PASSWORD={DB_PASSWORD}")
                    .WaitForPort("5432/tcp", 30000 /*30s*/)
                    .MountVolume(volume, "/var/lib/postgresql/data", MountType.ReadWrite)
                    .Build();

I'd like to be able to get the port for that container with something along the lines of this or whatever else makes sense

var docker = hosts.FirstOrDefault(x => x.IsNative) ?? hosts.FirstOrDefault(x => x.Name == "default");
var existingContainer = docker?.GetContainers().FirstOrDefault(c => c.Name == DB_CONTAINER_NAME);

// this should return whatever `freePort` was from above
var ports = existingContainer.GetConfiguration().Config.HostPorts.FirstOrDefault();

Metadata

Metadata

Assignees

Labels

enhancementunder-investigationA investigation is made around the issuewaiting-for-feedbackWaiting for someone to give feedback until this issue can be brought further.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions