BuildImageFromDockerFileAsync does not tag images correctly

Open
#667 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp, docker

Research direction

Start at BuildImageFromDockerfileAsync and inspect how ImageBuildParameters.Tags is translated into the Docker API request. Reproduce the supplied example against a Docker API service, checking the generated build request and resulting image tags. Done means the requested testingrepo:latest tag is applied rather than only the Dockerfile's FROM image tag.

Written by the indexing model from the issue text.

Description

Output of dotnet --info:

PM> dotnet --info
.NET SDK:
Version: 8.0.101
Commit: 6eceda187b
Workload version: 8.0.100-manifests.69afb982

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.101\

.NET workloads installed:
Workload version: 8.0.100-manifests.69afb982
There are no installed workloads to display.

Host:
Version: 8.0.1
Architecture: x64
Commit: bf5e279d92

.NET SDKs installed:
2.1.803 [C:\Program Files\dotnet\sdk]
3.1.101 [C:\Program Files\dotnet\sdk]
3.1.426 [C:\Program Files\dotnet\sdk]
7.0.100-rc.1.22431.12 [C:\Program Files\dotnet\sdk]
7.0.312 [C:\Program Files\dotnet\sdk]
8.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0-rc.1.22427.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.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.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0-rc.1.22426.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0-rc.1.22427.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.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.15

Steps to reproduce the issue:
Copy this code and run against a docker API service:

using (DockerClient RemoteDockerServer = new DockerClientConfiguration(new Uri($"https://dockerserver.com:8080"), CertCredentials).CreateClient())
{
using (var tarStream = new MemoryStream(TarBytes))
{
using (var ExtractedArchive = ArchiveFactory.Open(tarStream))
{
var TempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(TempDir);
foreach (var entry in ExtractedArchive.Entries)
{
if (!entry.IsDirectory)
{
entry.WriteToDirectory(TempDir, new ExtractionOptions()
{
ExtractFullPath = true,
Overwrite = true
});
}
}

        var DockerFilePath = Directory.GetFiles(TempDir, "Dockerfile", SearchOption.AllDirectories).FirstOrDefault();
        string Tag = $"testingrepo:latest}";
        if (DockerFilePath != null)
        {
            tarStream.Seek(0, SeekOrigin.Begin);
            var buildParams = new ImageBuildParameters
            {
                Dockerfile = DockerFilePath.Substring(TempDir.Length).Replace("\\", "/"),
                Tags = new List<string> {Tag  },
            };
            await RemoteDockerServer.Images.BuildImageFromDockerfileAsync(buildParams, tarStream, null, null, new Progress<JSONMessage>(), CancellationToken.None);
        }
    }
    
}

}

What actually happened?:
The docker image gets built fine but it the tagging gets set as nginx:alpine which is the FROM element within the dockerfile.

What did you expect to happen?:
I would have expected when using docker images ls for it to produce the following output:

testingrepo latest 2b70e4aaac6b 3 months ago 42.6MB

Additional information:

Dominant language
C#
Stars
2.4k
Forks
416
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/Docker.DotNet

All issues in dotnet/Docker.DotNet

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.