Description
await _dockerClient.Images.BuildImageFromDockerfileAsync
returns immediately and does not wait for the image to be created.
When debugging, put a breakpoint immediately after await CreateImageFromDockerFile(stream, "Dockerfile_test_builder", "builder");
In a separate terminal, execute the command docker images
. Initially, the image is not there. If I wait patiently, the image does appear after ~1 minute. Wait a little longer and it then gets labeled builder as expected. I can then continue and start the container successfully.
I have successfully awaited await _dockerClient.Images.CreateImageAsync
for other images I require within this solution using a similar approach.
Please could you advise?
private async Task CreateImageFromDockerFile(Stream stream, string dockerFile, string image)
{
var response = await _dockerClient.Images.BuildImageFromDockerfileAsync(stream, new
ImageBuildParameters
{
Dockerfile = dockerFile,
Tags = new List<string>
{
image,
}
}, CancellationToken.None);
}
private async Task PullImages()
{
var stream = File.OpenRead("docker.tar");
await CreateImageFromDockerFile(stream, "Dockerfile_test_builder", "builder");
...
...
...
}
Output of dotnet --info
:
.NET Core SDK (reflecting any global.json):
Version: 3.1.201
Commit: b1768b4ae7
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/3.1.201/
Host (useful for support):
Version: 3.1.3
Commit: 4a9f85e9f8
.NET Core SDKs installed:
3.1.100 [/usr/local/share/dotnet/sdk]
3.1.201 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
What version of Docker.DotNet?:
3.1.201
Steps to reproduce the issue:
- Create a tar file which includes a docker-file
- Debug the code, putting a break point at await CreateImageFromDockerFile(stream, "Dockerfile_test_builder", "builder");
- Step over to see that it is instantaneous.
- Check the docker images at another terminal and immediately see the image is not yet created.
- Wait for the image to be created.
- Continue execution of code in debugger to successfully create and start the container from the image.
What actually happened?:
await _dockerClient.Images.BuildImageFromDockerfileAsync didn't await for the creation to be complete.
What did you expect to happen?:
As with CreateImageAsync, I expected BuildImageFromDockerfileAsync to wait until the image as built.
Additional information:
Activity