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

Aperta
#80 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@AdzerKI ci sta già lavorando.

Dal 23/10/2026.

  • #81 di @AdzerKI — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
20/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
php
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
PHP
Stelle
216
Fork
38
Merge medio
1g 14h
PR unite (30g)
5

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di testcontainers/testcontainers-php

Tutte le issue di testcontainers/testcontainers-php

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.