testcontainers-dotnet: [Bug]: ImageFromDockerfileBuilder cannot build `Dockerfile` with intermediate layer (regression works with `3.3.0`)

Problem

I cannot give the docker directory to the ImageFromDockerfileBuilder, only the dockerfile is possible:

public ImageFromDockerfileBuilder WithDockerfile(string dockerfile)
    {
      return Merge(DockerResourceConfiguration, new ImageFromDockerfileConfiguration(dockerfile: dockerfile));
    }

I need to set the root to a certain directory so that the Copy instructions in my Dockerfile work.

Solution

I am not sure if this is enough, but consider this:

Add another method accepting the dockerfile and the directory.

public ImageFromDockerfileBuilder WithDockerfile(string dockerfile, string dockerfileDirectory)
    {
      return Merge(DockerResourceConfiguration, new ImageFromDockerfileConfiguration(dockerfile: dockerfile,
                                                                                     dockerfileDirectory: dockerfileDirectory));
    }

Benefit

This change could enable my use case for using the ImageFromDockerfileBuilder.

Alternatives

I am not sure if there are other alternatives, I don’t understand Docker well enough yet.

Would you like to help contributing this enhancement?

Yes

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 24

Most upvoted comments

Much appreciated. I will address the issue later this week. In the first fix, I will not include the resolution of Dockerfile ARGs (variables). I will likely ignore those lines, similar to the previous versions, and add support for ARGs (variables) afterward. I will focus on:

pull access denied for build, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

Maybe add " As " and " aS ", too? Looks good for me!

Thank you, that really helped me understand the problem much better. Testcontainers for .NET, tries to download each image from the Dockerfile in advance (this is necessary when the image is stored in a private registry). However, in your case, Testcontainers for .NET attempts to download images for the lines FROM build AS publish and FROM base AS final. These lines represent intermediate layers, not actual images that Testcontainers can download. As a result, an exception is thrown. If you remove these intermediate layers (similar to the WeatherForecast example), you should be able to use the latest version (3.4.0).

I am curious about how we can identify these intermediate build layers. @eddumelendez , do you have any idea how Java does it? Do we need to skip pulling images when we find the image name after the AS statement?