testcontainers / testcontainers/testcontainers-java
Option to ignore ports in docker-compose files
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
When using DockerComposeContainer to launch an existing docker-compose file, Testcontainers expose random ports for the services, which can be picked up with the .getServicePort(..., ...) method.
However, if the docker-compose file includes ports definitions, Testcontainers will also expose those fixed ports, defeating the purpose of avoiding collisions by randomizing ports.
I am aware that the documentations states that "it is not necessary to define ports to be exposed in the YAML file; this would inhibit reuse/inclusion of the file in other contexts". But at the same time, DockerComposeContainer is meant to be used in situations where docker-compose files are already in use, and for me, it is convenient that those existing docker-compose files do include the port definitions.
So it would be convenient if Testcontainers could simply ignore the ports in the docker-compose files, and only expose the randomly assigned numbers. As far as I can see, this is not currently an option(?)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing DockerComposeContainer and its getServicePort(...) handling to find where ports from an existing Compose file are exposed. Check the current Docker Compose integration tests, then define completion as an option that ignores fixed ports while retaining randomly assigned service ports and avoids host-port collisions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, docker-compose, java
- Domain
- devops, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100