testcontainers / testcontainers/testcontainers-java

Automatically map exposed ports defined in Dockerfile

Open
#1,448 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

resolution/acknowledged type/feature
Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

Typically a Docker image will declare what ports it exposes using:
EXPOSE <ports...>

Why is it also necessary to duplicate this information by default for GenericContainer?

Take the quick start example:

@Rule
public GenericContainer redis = new GenericContainer<>("redis:5.0.3-alpine")
                                        .withExposedPorts(6379);

If the user does not explicitly state what ports to expose via withExposedPorts(), could we run DockerClientFactory.instance().client().inspectImageCmd(this.getDockerImageName()).exec(); to run a Docker image inspection and automatically read/set the ports exposed by the Docker image? I know there are situations where a user may not want to expose all (or any) ports of a container, but I think this would be the minority case for Testcontainers users, right?

If we were to do this, the above code example could simply be:

@Rule
public GenericContainer redis = new GenericContainer<>("redis:5.0.3-alpine");

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 reading GenericContainer and its withExposedPorts handling, then inspect the DockerClientFactory.instance().client().inspectImageCmd(...) entry point described in the issue. Done means a GenericContainer can derive exposed ports from the image when none are specified, while the issue's explicit-port and no-port cases remain defined and verified.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.