Skip to content

[Bug]: ImageFromDockerfileBuilder breaking change in 4.8.0 #1557

@alexaka1

Description

@alexaka1

Testcontainers version

4.8.0

Using the latest Testcontainers version?

Yes

Host OS

Linux, MacOS

Host arch

x86, arm64

.NET version

9.0.306

Docker version

Client:
 Version:           28.5.1
 API version:       1.51
 Go version:        go1.24.8
 Git commit:        e180ab8
 Built:             Wed Oct  8 12:16:17 2025
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.48.0 (207573)
 Engine:
  Version:          28.5.1
  API version:      1.51 (minimum version 1.24)
  Go version:       go1.24.8
  Git commit:       f8215cc
  Built:            Wed Oct  8 12:18:25 2025
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.7.27
  GitCommit:        05044ec0a9a75232cad458027ca83437aae3f4da
 runc:
  Version:          1.2.5
  GitCommit:        v1.2.5-0-g59923ef
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client:
 Version:    28.5.1
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  ai: Docker AI Agent - Ask Gordon (Docker Inc.)
    Version:  v1.9.11
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-ai
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.29.1-desktop.1
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-buildx
  cloud: Docker Cloud (Docker Inc.)
    Version:  v0.4.39
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-cloud
  compose: Docker Compose (Docker Inc.)
    Version:  v2.40.0-desktop.1
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.44
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-debug
  desktop: Docker Desktop commands (Docker Inc.)
    Version:  v0.2.0
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-desktop
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.31
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.4.0
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-init
  mcp: Docker MCP Plugin (Docker Inc.)
    Version:  v0.23.0
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-mcp
  model: Docker Model Runner (Docker Inc.)
    Version:  v0.1.42
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-model
  offload: Docker Offload (Docker Inc.)
    Version:  v0.4.39
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-offload
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.18.3
    Path:     /Users/alexaka1/.docker/cli-plugins/docker-scout

Server:
 Containers: 7
  Running: 4
  Paused: 0
  Stopped: 3
 Images: 61
 Server Version: 28.5.1
 Storage Driver: overlayfs
  driver-type: io.containerd.snapshotter.v1
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Discovered Devices:
  cdi: docker.com/gpu=webgpu
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.10.14-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 12
 Total Memory: 46.97GiB
 Name: docker-desktop
 ID: aa7eda8c-ffd8-4bfc-b6bc-8c317e4d9cc3
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///Users/alexaka1/Library/Containers/com.docker.docker/Data/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

What happened?

My tests are unable to run on the Renovate branch that updates to 4.7.0: alexaka1/distroless-dotnet-healthchecks#869

For example here: https://github.com/alexaka1/distroless-dotnet-healthchecks/actions/runs/18673678080/job/53239457620?pr=869#step:10:27

It says:

/_/src/Docker.DotNet/DockerClient.cs(516): error test failed: Distroless.HealthChecks.Test.HealthyTests.Net10.Runtime10AotContainerTest.Container_is_healthy(image: "mcr.microsoft.com/dotnet/nightly/runtime", runtimeTag: "10.0-preview@sha256:89f9ea57c1245b919a5f9bd94226d9"···, targetFramework: "10.0", dockerfile: "test/Distroless.Sample.WebApp/Dockerfile") (22s 904ms): Docker.DotNet.DockerApiException : Docker API responded with status code=InternalServerError, response={"message":"Cannot locate specified Dockerfile: test/Distroless.Sample.WebApp/Dockerfile"} [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:  [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed: Stack Trace: [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:    at Docker.DotNet.DockerClient.HandleIfErrorResponseAsync(HttpStatusCode statusCode, HttpResponseMessage response) in /_/src/Docker.DotNet/DockerClient.cs:line 516 [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:    at Docker.DotNet.DockerClient.MakeRequestForRawResponseAsync(HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary`2 headers, CancellationToken token) in /_/src/Docker.DotNet/DockerClient.cs:line 331 [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:    at Docker.DotNet.Models.StreamUtil.MonitorResponseForMessagesAsync[T](Task`1 responseTask, DockerClient client, CancellationToken cancel, IProgress`1 progress) in /_/src/Docker.DotNet/Endpoints/StreamUtil.cs:line 80 [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:    at DotNet.Testcontainers.Clients.DockerImageOperations.BuildAsync(IImageFromDockerfileConfiguration configuration, ITarArchive dockerfileArchive, CancellationToken ct) in /_/src/Testcontainers/Clients/DockerImageOperations.cs:line 122 [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:    at DotNet.Testcontainers.Clients.TestcontainersClient.BuildAsync(IImageFromDockerfileConfiguration configuration, CancellationToken ct) in /_/src/Testcontainers/Clients/TestcontainersClient.cs:line 398 [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:    at DotNet.Testcontainers.Images.FutureDockerImage.UnsafeCreateAsync(CancellationToken ct) in /_/src/Testcontainers/Images/FutureDockerImage.cs:line 145 [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:    at DotNet.Testcontainers.Images.FutureDockerImage.CreateAsync(CancellationToken ct) in /_/src/Testcontainers/Images/FutureDockerImage.cs:line 112 [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:    at Distroless.HealthChecks.Test.HealthyTests.HealthyContainerTest`1.Init(TestData data, CancellationToken cancellationToken) in /home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/HealthyTests/HealthyContainerTest.cs:line 96 [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:    at Distroless.HealthChecks.Test.HealthyTests.HealthyContainerTest`1.Container_is_healthy(String image, String runtimeTag, String targetFramework, String dockerfile) in /home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/HealthyTests/HealthyContainerTest.cs:line 44 [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed:    at Distroless.HealthChecks.Test.HealthyTests.HealthyContainerTest`1.Container_is_healthy(String image, String runtimeTag, String targetFramework, String dockerfile) in /home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/HealthyTests/HealthyContainerTest.cs:line 60 [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]
/_/src/Docker.DotNet/DockerClient.cs(516): error test failed: --- End of stack trace from previous location --- [/home/runner/work/distroless-dotnet-healthchecks/distroless-dotnet-healthchecks/test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj]

My tests basically do the following:

  • build an image from a dockerfile
  • configure a container with said image
  • run tests
string baseImageType = Utils.CurrentBaseImageType();
        string healthCheckImage = Utils.HealthCheckImage();
        _image = new ImageFromDockerfileBuilder()
            .WithDockerfile(data.Dockerfile)
            .WithBuildArgument("RUNTIME_TAG", data.RuntimeTag)
            .WithBuildArgument("TARGET_FRAMEWORK", data.TargetFramework)
            .WithBuildArgument("IMAGE", data.Image)
            .WithBuildArgument("BASE_IMAGE_TYPE", baseImageType)
            .WithBuildArgument("HEALTHCHECK_IMAGE", healthCheckImage)
            .WithDockerfileDirectory(CommonDirectoryPath.GetSolutionDirectory(), "")
            .Build();
        await _image.CreateAsync(cancellationToken)
            .ConfigureAwait(false); // <---- exception here ##########################
        _container = new ContainerBuilder()
            .WithImage(_image)
            .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged(
                    Regex.Escape("Application started. Press Ctrl+C to shut down."),
                    strategy => strategy.WithTimeout(TimeSpan.FromSeconds(30)))
                .UntilContainerIsHealthy(3,
                    strategy => strategy.WithTimeout(TimeSpan.FromSeconds(30)))
            )
            .WithEnvironment("DISTROLESS_HEALTHCHECKS_Uri", "http://localhost:8080/healthz")
            .Build();

And every single one of them fails when it comes to building the dockerfile.

Relevant log output

Additional information

With .NET 9 SDK and docker installed, check out this repo and run one of the test classes

CI=true dotnet test -c Release test/Distroless.HealthChecks.Test/Distroless.HealthChecks.Test.csproj -- --filter-class "*AspNet9AotContainerTest*" 

The project has a lot of tests, so don't just blanket run all of them, or else you'll be sitting there for a good while.

The tests fail both locally on macos and in CI on ubuntu-latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions