Client-side host port pick collides with ports already in use

Abierto
#80 0 comentarios 0 reacciones 0 asignados Ver en GitHub

@AdzerKI ya está trabajando en esto.

Desde el 23/10/2026.

  • #81 de @AdzerKI — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
20/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
php
Área
backend

Línea de trabajo

Start with GenericContainer's default host port binding and compare it with the daemon allocated port flow described in the issue. Check how getMappedPort() reads NetworkSettings.Ports, then verify that withPortGenerator() still supports fixed ports. Done means the default binding leaves HostPort unset and the mapped port is available after start; pull request #81 is already open for this change.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

GenericContainer picks host ports on its own: RandomUniquePortGenerator takes a random port from 10000–65535 and only checks that nothing accepts connections on localhost:<port>. The port can still be taken between that check and the container start, or be bound without a listener — for example as the local port of an outgoing connection, when the host's ephemeral range overlaps 10000–65535. The start then fails:

Docker\API\Exception\ContainerStartInternalServerErrorException: server error
rootlessport listen tcp 0.0.0.0:16544: bind: address already in use

We hit this a few times a week on a CI host that runs test suites in parallel (rootless Podman, net.ipv4.ip_local_port_range = 10000 65535).

Other Testcontainers implementations leave host port allocation to the daemon: the binding goes out without HostPort, and the mapped port is read from NetworkSettings.Ports after start. getMappedPort() already reads it from inspect, so only the default binding has to change, while withPortGenerator() keeps working for fixed ports.

I'll open a PR with this change.

Lenguaje dominante
PHP
Estrellas
216
Forks
38
Merge medio
1 d 14 h
PR fusionados (30 d)
5

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de testcontainers/testcontainers-php

Todos los issues de testcontainers/testcontainers-php

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.