dezzy
dezzy

Reputation: 495

In Docker.DotNet how do you build an image by specifying the directory of the Dockerfile?

I am trying to build an image and start a container, for the purposes of integration testing, in a C# xunit test. I currently have the code below, but can't find away to specify the path to the docker file. The client does have Images.BuildImageFromDockerfileAsync but that deals with unpacking TAR files.

        using(var client = new DockerClientConfiguration(
            new Uri(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) 
                ? "npipe://./pipe/docker_engine"
                : "unix:/var/run/docker.sock")).CreateClient())
        {
            await client
                .Images
                .CreateImageAsync(
                    new ImagesCreateParameters(),
                    new AuthConfig(),
                    new Progress<JSONMessage>());

        }

I want to do the equivalent of docker build -t yyyy -f ./zzzzzz/Dockerfile . using the Docker.DotNet api but I can't work out a way to do it. Any help would be kindly appreciated.

Upvotes: 3

Views: 1930

Answers (1)

maxm
maxm

Reputation: 3667

The docker build command effectively creates a Tar of the entire working directory and sends it to the build daemon. So much so that if you run docker build - it will expect a tar stream from stdin.

You could do something like this to tar up the build directory and pass it to BuildImageFromDockerFileAsync: https://github.com/dotnet/Docker.DotNet/issues/309#issuecomment-547316442

Upvotes: 3

Related Questions