Repository navigation
Fail the start when the container exits before its ports are bound - #1513
Draft
cristianrgreco wants to merge 1 commit into
Draft
cristianrgreco wants to merge 1 commit into
cristianrgreco wants to merge 1 commit into
Conversation
This was referenced Oct 12, 2026
cristianrgreco
marked this pull request as draft
October 13, 2026 15:55
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A container that exits before its ports are bound, for example one that crashes immediately on startup, held
start()for 30 seconds and then failed withTimed out after 30000ms while waiting for container ports to be bound to the host, whatever the wait strategy. An exited container never reports port bindings, so the wait could not succeed.start()fails straight away withContainer exited with code <code> before its ports were bound to the host.restartingunder a restart policy is still waited on: Docker only reportsexitedonce the policy gives up.The same helper is used by
start(), container reuse andrestart().This follows testcontainers-go, whose host port wait checks the container state on every retry while polling for the mapped port (
wait/host_port.go). testcontainers-java and testcontainers-dotnet do not check the state at this step.Related to #1507 and #1512, which fix the same problem inside the HTTP wait strategy.
Verification
format,lint,knip,check-compiles: clean.inspect-container-util-ports-exposed.test.ts: 9 tests passed.should follow symlink when copying file to started containergot exec exit code 128 instead of 1; it passed alone andgeneric-container.test.tspassed in full on rerun (51 passed, 1 skipped). It does not exercise the changed code.Red-green
throws an error when the container exits before its ports are exposed:Test timed out in 5000ms, because the helper keeps polling an exited container.End to end, a container with entrypoint
exit 1and an exposed port took 30s to fail before the fix and about 0.3s after it, three runs out of three.There is no integration test: whether the first inspect sees an immediately exiting container as still running or already exited depends on timing inside the Docker daemon, so the unit tests cover the logic deterministically instead.
Not breaking