testcontainers/testcontainers-java · warning

A large amount of data was sent to the Docker daemon

Error message

A large amount of data was sent to the Docker daemon ({}). Consider using a .dockerignore file for better performance.

What it means

When ImageFromDockerfile streams the build context tarball to the Docker daemon, it counts bytes and warns when more than 50MB is transferred. Large contexts slow builds dramatically; the common cause is accidentally including build artifacts, node_modules, or big data files because there is no .dockerignore.

Solutions

  1. Add a .dockerignore (or use withFileFromString/.dockerignore support) to exclude build outputs, .git, and deps
  2. Build context from a minimal directory containing only files the Dockerfile COPYs
  3. Copy individual files with withFileFromString/withFileFromClasspath instead of whole directories

Example fix

// before
new ImageFromDockerfile().withFileFromPath(".", projectRoot)
// after: dockerignore excluding junk
new ImageFromDockerfile()
    .withFileFromString(".dockerignore", "target\nnode_modules\n.git\n*.log")
    .withFileFromPath(".", projectRoot);
Defensive patterns

Strategy: validation

Validate before calling

long size = Files.walk(contextDir).mapToLong(p -> p.toFile().length()).sum();
if (size > 50L * 1024 * 1024) {
    throw new IllegalStateException("Build context too large: " + size + " bytes — add .dockerignore");
}

Prevention

When it happens

Trigger: ImageFromDockerfile.resolve() (via imageId) finishes transferring the tar archive and bytesToDockerDaemon > 50MB.

Common situations: withFileFromDirectory pointing at a project root without a .dockerignore; copying target/, node_modules/, .git, or datasets into the build context; Dockerfile-based images built in CI from large monorepo directories.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


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

Appendix: source

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

            long bytesToDockerDaemon = 0;

            // To build an image, we have to send the context to Docker in TAR archive format
            try (TarArchiveOutputStream tarArchive = new TarArchiveOutputStream(new GZIPOutputStream(out))) {
                tarArchive.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
                tarArchive.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);

                for (Map.Entry<String, Transferable> entry : transferables.entrySet()) {
                    Transferable transferable = entry.getValue();
                    final String destination = entry.getKey();
                    transferable.transferTo(tarArchive, destination);
                    bytesToDockerDaemon += transferable.getSize();
                }
                tarArchive.finish();
            }

            log.info("Transferred {} to Docker daemon", FileUtils.byteCountToDisplaySize(bytesToDockerDaemon));
            if (bytesToDockerDaemon > FileUtils.ONE_MB * 50) {
                log.warn( // warn if >50MB sent to docker daemon
                    "A large amount of data was sent to the Docker daemon ({}). Consider using a .dockerignore file for better performance.",
                    FileUtils.byteCountToDisplaySize(bytesToDockerDaemon)
                );
            }

            exec.awaitImageId();

            return dockerImageName;
        } catch (IOException e) {
            throw new RuntimeException("Can't close DockerClient", e);
        }
    }

    protected void configure(BuildImageCmd buildImageCmd) {
        buildImageCmd.withTags(Collections.singleton(getDockerImageName()));
        this.dockerFilePath.ifPresent(buildImageCmd::withDockerfilePath);
        this.dockerfile.ifPresent(p -> {
                buildImageCmd.withDockerfile(p.toFile());

View on GitHub (pinned to 8e549514e3)