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

Ouverte
#80 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

@AdzerKI y travaille déjà.

Depuis le 23/10/2026.

  • #81 par @AdzerKI — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
20/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
php
Domaine
backend

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
PHP
Étoiles
216
Forks
38
Merge moyen
1 j 14 h
PR mergées (30 j)
5

Préparer son environnement

  • Fournit un Dockerfile ou un fichier Docker Compose
  • Aucun modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de testcontainers/testcontainers-php

Toutes les issues de testcontainers/testcontainers-php

Issues similaires

Plus d'issues PHP

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.