Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await BuildImageFromDockerfileAsync returns before image is created #445

Closed
lmckechnie opened this issue May 1, 2020 · 2 comments · Fixed by #507 · May be fixed by #451
Closed

await BuildImageFromDockerfileAsync returns before image is created #445

lmckechnie opened this issue May 1, 2020 · 2 comments · Fixed by #507 · May be fixed by #451

Comments

@lmckechnie
Copy link

lmckechnie commented May 1, 2020

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:

  1. Create a tar file which includes a docker-file
  2. Debug the code, putting a break point at await CreateImageFromDockerFile(stream, "Dockerfile_test_builder", "builder");
  3. Step over to see that it is instantaneous.
  4. Check the docker images at another terminal and immediately see the image is not yet created.
  5. Wait for the image to be created.
  6. 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:

@jhenkens
Copy link
Contributor

I appear to have hit this as well. More importantly, it appears there is no handling of the output of this API call to properly record errors, at least in my situation. The raw command output is passed into the Stream returned by the call. It appears this API call has not been completed in this library, and is in an MVP state.

@ConnorChristie
Copy link

To ensure the image has been created, you have to read the stream that is returned. However, I have also had problems doing this and the stream being forcibly closed after reading to the end but I just surrounded that with a try-catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants