Repository navigation
Closed
Description
Expected Behaviour
GenericContainer.fromDockerfile().build() should extract the base image name from valid Dockerfile FROM instructions, including FROM --platform=<platform> <image>, tab-separated FROM lines, \ line continuations, and ARG defaults declared before FROM, so getRegistryConfig resolves credentials for private base registries instead of falling back to Docker Hub or throwing.
Actual Behaviour
parseImages in packages/testcontainers/src/utils/dockerfile-parser.ts splits each FROM line on " " and takes token [1], and getDockerfileImages only substitutes ${arg} from .withBuildArgs() without reading ARG defaults from the Dockerfile:
FROM --platform=linux/amd64 myreg.example.com/team/base:1.2 AS buildparses--platform=linux/amd64:latest(registry: undefined), sogetRegistryConfiglooks uphttps://index.docker.io/v1/instead ofmyreg.example.comand sends no credentials for the private registry.FROM\tghcr.io/org/app:2producesundefinedat index1and rejects.build()before calling Docker withTypeError: Cannot read properties of undefined (reading 'replace').ARG BASE=private.io/x/y:3followed byFROM ${BASE}(whenBASEis not overridden via.withBuildArgs()) substitutes""and parses:latest(registry: undefined).FROM \followed byghcr.io/org/app:2parses\:latest(registry: undefined).
Testcontainers Logs
2026-11-14T10:42:11.152Z testcontainers [DEBUG] Checking container runtime strategy "TestcontainersHostStrategy"...
2026-11-14T10:42:11.153Z testcontainers [DEBUG] Container runtime strategy "TestcontainersHostStrategy" is not applicable
2026-11-14T10:42:11.153Z testcontainers [DEBUG] Checking container runtime strategy "ConfigurationStrategy"...
2026-11-14T10:42:11.154Z testcontainers [DEBUG] Container runtime strategy "ConfigurationStrategy" is not applicable
2026-11-14T10:42:11.157Z testcontainers [DEBUG] Checking container runtime strategy "UnixSocketStrategy"...
2026-11-14T10:42:11.158Z testcontainers [TRACE] Fetching Docker info...
2026-11-14T10:42:11.185Z testcontainers [TRACE] Fetching remote container runtime socket path...
2026-11-14T10:42:11.185Z testcontainers [TRACE] Resolving host...
2026-11-14T10:42:11.185Z testcontainers [TRACE] Fetching Compose info...
2026-11-14T10:42:11.186Z testcontainers [TRACE] Looking up host IPs...
2026-11-14T10:42:11.193Z testcontainers [TRACE] Initialising clients...
2026-11-14T10:42:11.193Z testcontainers [TRACE] Container runtime info:
{
"node": {
"version": "v26.13.0",
"architecture": "x64",
"platform": "linux"
},
"containerRuntime": {
"host": "localhost",
"hostIps": [
{
"address": "::1",
"family": 6
},
{
"address": "127.0.0.1",
"family": 4
}
],
"remoteSocketPath": "/var/run/docker.sock",
"indexServerAddress": "https://index.docker.io/v1/",
"serverVersion": "20.10.24+dfsg1",
"operatingSystem": "Debian GNU/Linux 12 (bookworm)",
"operatingSystemType": "linux",
"architecture": "x86_64",
"cpus": 64,
"memory": 270458503168,
"runtimes": [
"io.containerd.runc.v2",
"io.containerd.runtime.v1.linux",
"runc"
],
"labels": []
}
}
2026-11-14T10:42:11.193Z testcontainers [DEBUG] Container runtime strategy "UnixSocketStrategy" works
2026-11-14T10:42:11.195Z testcontainers [DEBUG] Acquiring lock file "/tmp/testcontainers-node-1010.lock"...
2026-11-14T10:42:11.197Z testcontainers [DEBUG] Acquired lock file "/tmp/testcontainers-node-1010.lock"
2026-11-14T10:42:11.197Z testcontainers [DEBUG] Listing containers...
2026-11-14T10:42:11.201Z testcontainers [DEBUG] Listed containers
2026-11-14T10:42:11.201Z testcontainers [DEBUG] Releasing lock file "/tmp/testcontainers-node-1010.lock"...
2026-11-14T10:42:11.201Z testcontainers [DEBUG] Released lock file "/tmp/testcontainers-node-1010.lock"
2026-11-14T10:42:11.202Z testcontainers [DEBUG] No auth config found for registry "https://index.docker.io/v1/"
2026-11-14T10:42:11.202Z testcontainers [INFO] Building Dockerfile "/tmp/tc-e2e-Xgcv1j/Dockerfile" as image "localhost/c6a45f753b3e:c230e677376b"...
2026-11-14T10:42:11.203Z testcontainers [DEBUG] Building image "localhost/c6a45f753b3e:c230e677376b" with context "/tmp/tc-e2e-Xgcv1j"...
2026-11-14T10:42:11.273Z testcontainers:build [localhost/c6a45f753b3e:c230e677376b] {"stream":"Step 1/5 : FROM --platform=linux/amd64 127.0.0.1:59999/team/base:1.2 AS build"}
2026-11-14T10:42:11.273Z testcontainers:build [localhost/c6a45f753b3e:c230e677376b] {"stream":"\n"}
2026-11-14T10:42:11.276Z testcontainers:build [localhost/c6a45f753b3e:c230e677376b] {"errorDetail":{"message":"Get \"http://127.0.0.1:59999/v2/\": dial tcp 127.0.0.1:59999: connect: connection refused"},"error":"Get \"http://127.0.0.1:59999/v2/\": dial tcp 127.0.0.1:59999: connect: connection refused"}
2026-11-14T10:42:11.278Z testcontainers [DEBUG] Built image "localhost/c6a45f753b3e:c230e677376b" with context "/tmp/tc-e2e-Xgcv1j"
2026-11-14T10:42:11.279Z testcontainers [DEBUG] Checking if image exists "localhost/c6a45f753b3e:c230e677376b"...
2026-11-14T10:42:11.280Z testcontainers [DEBUG] Checked if image exists "localhost/c6a45f753b3e:c230e677376b"
Steps to Reproduce
- Install
testcontainers@12.2.1(npm install testcontainers@12.2.1). - Save
repro.cjs:
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const { getDockerfileImages } = require("testcontainers/build/utils/dockerfile-parser.js");
const cases = {
platform: "FROM --platform=linux/amd64 myreg.example.com/team/base:1.2 AS build\n",
tab: "FROM\tghcr.io/org/app:2\n",
argDefault: "ARG BASE=private.io/x/y:3\nFROM ${BASE}\n",
continuation: "FROM \\\n ghcr.io/org/app:2\n",
};
(async () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "tc-repro-"));
try {
for (const [name, content] of Object.entries(cases)) {
const file = path.join(tmp, name);
fs.writeFileSync(file, content);
try {
const images = await getDockerfileImages(file, {});
console.log(name, images.map((i) => ({ string: i.string, registry: i.registry })));
} catch (err) {
console.log(name, "throws", `${err.name}: ${err.message}`);
}
}
} finally {
fs.rmSync(tmp, { recursive: true, force: true });
}
})();- Run
node repro.cjs. - Output:
platform [ { string: '--platform=linux/amd64:latest', registry: undefined } ]
tab throws TypeError: Cannot read properties of undefined (reading 'replace')
argDefault [ { string: ':latest', registry: undefined } ]
continuation [ { string: '\\:latest', registry: undefined } ]
Environment Information
- Operating System: Debian GNU/Linux 12 (Linux 6.1.0-54-cloud-amd64 x86_64)
- Container runtime and version: Docker Engine 20.10.24
- Node version: v26.13.0
- Test runner and version: Standalone Node script (CommonJS)
- Testcontainers version: testcontainers@12.2.1 (also reproduced on
mainatc79a5a5) - Last Testcontainers version where this worked, if any: None
Credit: https://ucsbplse.github.io/
Metadata
Metadata
Assignees
Labels
No labels
Activity