testcontainers/testcontainers-java · warning

overriding previous mapping for

Error message

overriding previous mapping for '{}'

What it means

ImageFromDockerfile.withFileFromTransferable stores files to copy into the image build context in a map keyed by path. If you register a second Transferable under a path that already has one, the previous entry is silently replaced and only a WARN is logged. The build proceeds with the last registered file.

Solutions

  1. Use a unique destination path for each withFileFromTransferable call
  2. If overriding is intentional, ignore the warning or restructure so each build has a fresh ImageFromDockerfile instance
  3. Remove or conditionalize the earlier registration if the first file is truly unwanted

Example fix

// before
image.withFileFromString("/app/conf.txt", "old").withFileFromString("/app/conf.txt", "new");
// after
image.withFileFromString("/app/conf.txt", "new");
Defensive patterns

Strategy: validation

Validate before calling

Set<String> seen = new HashSet<>();
void addFile(ImageFromDockerfile image, String path, String content) {
    if (!seen.add(path)) {
        throw new IllegalStateException("Duplicate path registered: " + path);
    }
    image.withFileFromString(path, content);
}

Prevention

When it happens

Trigger: Calling withFileFromTransferable(path, ...) (or convenience methods like withFileFromString/withFileFromClasspath) twice with the same path string on the same ImageFromDockerfile instance.

Common situations: Building images in loops where the same destination path (e.g. /app/config.yml) is reused across iterations; copying framework helpers that internally register a file at a path the user also uses.

Related errors


AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12). Data as JSON: /api/errors/da1a4f760d5d78d6. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/testcontainers/images/builder/ImageFromDockerfile.java:90

    public ImageFromDockerfile() {
        this("localhost/testcontainers/" + Base58.randomString(16).toLowerCase());
    }

    public ImageFromDockerfile(String dockerImageName) {
        this(dockerImageName, true);
    }

    public ImageFromDockerfile(String dockerImageName, boolean deleteOnExit) {
        this.dockerImageName = dockerImageName;
        this.deleteOnExit = deleteOnExit;
    }

    @Override
    public ImageFromDockerfile withFileFromTransferable(String path, Transferable transferable) {
        Transferable oldValue = transferables.put(path, transferable);

        if (oldValue != null) {
            log.warn("overriding previous mapping for '{}'", path);
        }

        return this;
    }

    @Override
    protected final String resolve() {
        Logger logger = DockerLoggerFactory.getLogger(dockerImageName);

        //noinspection resource
        DockerClient dockerClient = DockerClientFactory.instance().client();

        try {
            BuildImageResultCallback resultCallback = new BuildImageResultCallback() {
                @Override
                public void onNext(BuildResponseItem item) {
                    super.onNext(item);

View on GitHub (pinned to 8e549514e3)