Repository navigation
Fix Dockerfile FROM parsing for --platform, tabs, line continuations and ARG defaults - #1646
Merged
cristianrgreco merged 3 commits intoNov 19, 2026
Conversation
Collaborator
|
Hi @Pushkar236, is this PR ready for review? |
cristianrgreco
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for this, it looks good, and the red/green evidence helps. Two small points inline, neither blocking. Once they're addressed, mark the PR ready for review.
Pushkar236
marked this pull request as ready for review
November 15, 2026 11:12
Contributor
Author
|
Thanks for the review. Both points are addressed in d6793c4, so I've marked it ready. |
cristianrgreco
approved these changes
Nov 15, 2026
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
GenericContainer.fromDockerfile().build()reads the base images from the Dockerfile so it can send registry credentials for them. The parser split eachFROMline on a single space and took the second token, so:FROM --platform=linux/amd64 myreg.example.com/team/base:1.2was read as the image--platform=linux/amd64, and no credentials were sent formyreg.example.com.FROM<tab>ghcr.io/org/app:2threwTypeError: Cannot read properties of undefined (reading 'replace')before the build started.FROM \continuation was read as the image\.ARG BASE=private.io/x/y:3/FROM ${BASE}resolved to an empty image name unlessBASEwas also passed with.withBuildArgs().The parser now reads instructions the way Docker does for the parts that matter here: it joins continuation lines (honouring the
# escape=parser directive), skips comment and blank lines, splits on any whitespace, skips--flags onFROM, and uses defaults fromARGs declared before the firstFROM, with build args taking precedence.testcontainers-java's
ParsedDockerfilealso skips--flags onFROM; it doesn't handle continuations orARGdefaults, so those follow the Dockerfile reference instead. testcontainers-go splits on a single space like the old code here.Still not handled, unchanged from before:
$VARwithout braces,${VAR:-default}modifiers, andARGdefaults that reference otherARGs.Verification
main,npx vitest run packages/testcontainers/src/utils/dockerfile-parser.test.tsfails 5 of 12 (--platform, tabs, continuations, escape directive,ARGdefaults). The tabs case fails with theTypeErrorfrom the issue.npm run format,npm run lint,npm run knipandtsc --noEmit -p packages/testcontainersare clean.generic-container-dockerfile.test.tsagainst Docker 29.9.2 on macOS: 9/10 per run both onmainand on this branch, with a different test failing each run on both. I couldn't get a fully green run of that file locally either way.Not breaking
Dockerfiles the old parser handled produce the same images. The only behaviour change is for inputs it misparsed or threw on.
Suggested labels:
bug,patch.Closes #1643