Skip to content

How do I publish a random port? #678

Open

Description

I'm attempting to dynamically assign a random port to a container upon its creation. I've been experimenting with various configurations, including setting the PortBindings property to null and trying different values for HostPort such as 0, null, an empty string, and "0". However, I haven't been successful in achieving the desired outcome. Here's the snippet of code I've been working with:

CreateContainerParameters containerParameters = new CreateContainerParameters {
    Name = name,
    Image = type,
    HostConfig = new HostConfig {
        PortBindings = new Dictionary<string, IList<PortBinding>> {
            { "25565/tcp", [] }
        }
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions