Docker.DotNet
Docker.DotNet copied to clipboard
Docker.DotNet seems to return InternalServerError from Docker for all errors (even for 4** status codes)
I have been noticing that we always get InternalServerError from the docker daemon for any kind of issues. Today, I was trying to test out a case where we should be getting unauthorized, but we still end up getting InternalServerError.
Output of dotnet --info
:
PS C:\windows\system32> dotnet --info
.NET Command Line Tools (2.0.2)
Product Information: Version: 2.0.2 Commit SHA-1 hash: a04b4bf512
Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.0.2\
Microsoft .NET Core Shared Framework Host
Version : 2.0.0 Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
What version of Docker.DotNet?: 3.125
Steps to reproduce the issue:
- Try getting an image from a registry with invalid credentials.
Expected unauthorized but we still get InternalServerError.:
Docker.DotNet.DockerApiException: Docker API responded with status code=InternalServerError, response=
at Docker.DotNet.DockerClient.HandleIfErrorResponse(HttpStatusCode statusCode, String responseBody, IEnumerable1 handlers) at Docker.DotNet.DockerClient.<MakeRequestForStreamAsync>d__50.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Docker.DotNet.Models.StreamUtil.<MonitorStreamForMessagesAsync>d__1
1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
However, Docker logs via Get-EventLog -LogName Application -Source Docker -After (Get-Date).AddMinutes(-15) | Select Message produces
Handler for POST /v1.25/images/create returned error: unauthorized: authentication required Attempting next endpoint for pull after error: unauthorized: authentication required debug: Trying to pull myownrepo.azurecr.io/tanks2 from myownrepo.xcloudcr.azurecr.io v2
Looking at the code, I don't think this is a problem with Docker DotNet, but just wanted to check with the community here. It seems weird that docker would have one thing in the event log but return another. The docker API https://docs.docker.com/engine/api/v1.25/#operation/ImageCreate says we should get 4** status code
I'm looking into this issue as well.
I do believe that this is a docker.dotnet client issue. docker cli can print "unauthorized: authentication required" and so does the python client. The DockerApiException, on docker.dotnet, however, doesn't have this information. Here's the message of the exception that I observe: Docker.DotNet.DockerApiException: 'Docker API responded with status code=InternalServerError, response=' It looks to me like the essential information got lost in translation.
Here's what I see in debugger for what's being read from the named pipe:
HTTP/1.1 500 Internal Server Error
Api-Version: 1.35
Content-Length: 52
Content-Type: application/json
Date: Thu, 01 Feb 2018 08:26:49 GMT
Docker-Experimental: true
Ostype: windows
Server: Docker/17.12.0-ce (windows)
Connection: close
{"message":"unauthorized: authentication required"}.
@SedarG Experiencing the same issue, not sure if you ever figured it out?
What version of Docker.DotNet are you using? Our respond handler seems to handle this case on error by reading the body and assigning this to the DockerApiException
message.
In case it helps someone else, I got this same (unhelpful) error when my docker file referenced a local image which hadn't yet been created