dotnet / dotnet/Docker.DotNet

Docket.DotNet Build Image has undocumented limitations

Open
#635 6 comments 5 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2.4k
Forks
416
PR merge metrics
No merged PRs in 30d

Description

**Output of `dotnet --info`:**
```
.NET SDK:
Version: 7.0.101
Commit: bb24aafa11

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.101\

Host:
Version: 7.0.1
Architecture: x64
Commit: 97203d38ba

.NET SDKs installed:
6.0.100 [C:\Program Files\dotnet\sdk]
7.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download
```

**What version of Docker.DotNet?:**

```
3.125.14
```

**Steps to reproduce the issue:**
Dockerfile
```
FROM debian
WORKDIR /data
COPY --chmod=+x . /data
```

Code (ConsoleApp calling BuildImageFromDockerfileAsync)
```
using Docker.DotNet;
using Docker.DotNet.Models;
using System.Text;
using ICSharpCode.SharpZipLib.Tar;

using var client = new DockerClientConfiguration(new Uri("npipe://./pipe/docker_engine"))
.CreateClient();

await BuildDockerImage(client, ".");

static async Task BuildDockerImage(DockerClient client, string dockerFileDirectory)
{
// Create an ImageBuildParameters object
var buildParameters = new ImageBuildParameters
{
Dockerfile = "Dockerfile",
Remove = true, // Remove intermediate containers after a successful build
Tags = new[] { "yourimagename:tag" }, // Set your image name and tag
ForceRemove = true, // Always remove intermediate containers, even upon failure
NoCache = true // Do not use the cache when building the image,
};

// Read the dockerfile content
var dockerFileContent = File.ReadAllText(Path.Combine(dockerFileDirectory, buildParameters.Dockerfile));

// Create a tarball with the Dockerfile
var tarball = new FileStream("new.tar", FileMode.Create);
await using (var tarArchive = new TarOutputStream(tarball))
{
var tarEntry = TarEntry.CreateTarEntry("Dockerfile");
var fileBytes = Encoding.UTF8.GetBytes(dockerFileContent);
tarEntry.Size = fileBytes.Length;
tarArchive.PutNextEntry(tarEntry);
tarArchive.Write(fileBytes, 0, fileBytes.Length);
tarArchive.CloseEntry();
}

tarball = new FileStream("new.tar", FileMode.Open);

// Build the image
await using (var responseStream = await client.Images.BuildImageFromDockerfileAsync(tarball, buildParameters))
{
// Read the response from the Docker API
using var reader = new StreamReader(responseStream);
while (!reader.EndOfStream)
{
var line = await reader.ReadLineAsync();
Console.WriteLine(line);
}
}
}
```

**What actually happened?:**
```
{"errorDetail":{"message":"the --chmod option requires BuildKit. Refer to https://docs.docker.com/go/buildkit/ to learn how to build images with BuildKit enabled"},"error":"the --chmod option requires BuildKit. Refer to https://docs.docker.com/go/buildkit/ to learn how to build images with BuildKit enabled"}
```

**What did you expect to happen?:**
Image is created equivalent to doing `docker build` on the command line.

**Additional information:**
https://github.com/moby/moby/issues/41711#issuecomment-733281140

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.