testcontainers / testcontainers-dotnet

A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.

Home Page:https://dotnet.testcontainers.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker API responded with status code=ProxyAuthenticationRequired, response=Please run 'docker login'

MrClyfar opened this issue · comments

Testcontainers version

3.6.0

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host arch

x86

.NET version

.NET 6

Docker version

Client:
 Cloud integration: v1.0.35+desktop.5
 Version:           24.0.6
 API version:       1.43
 Go version:        go1.20.7
 Git commit:        ed223bc
 Built:             Mon Sep  4 12:32:48 2023
 OS/Arch:           windows/amd64
 Context:           default

Server: Docker Desktop 4.24.1 (123237)
 Engine:
  Version:          24.0.6
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.7
  Git commit:       1a79695
  Built:            Mon Sep  4 12:32:16 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.22
  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca
 runc:
  Version:          1.1.8
  GitCommit:        v1.1.8-0-g82f18fe
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client:
 Version:    24.0.6
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2-desktop.5
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.22.0-desktop.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.20
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.8
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scan.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.0.7
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 6
 Server Version: 24.0.6
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8165feabfdfe38c65b599c4993d227328c231fca
 runc version: v1.1.8-0-g82f18fe
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.90.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 15.51GiB
 Name: docker-desktop
 ID: 741aefd8-b184-4a99-83f8-19550a27090c
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile

What happened?

I am trying out the Testcontainers lib with an XUnit project. Given the following constructor where I am trying to build a container using an image that is stored locally (I can see it in Docker Desktop as "property" with tag "service")

public HttpTest()
{
    container = new ContainerBuilder()
        .WithImage("property:service")
        .WithPortBinding(8080, true)
        .WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(8080)))
        .Build();
}

When running the unit test I get this error when executing the constructor code.

Docker.DotNet.DockerApiException
Docker API responded with status code=ProxyAuthenticationRequired, response=Please run 'docker login'

   at Docker.DotNet.DockerClient.HandleIfErrorResponseAsync(HttpStatusCode statusCode, HttpResponseMessage response)
   at Docker.DotNet.DockerClient.MakeRequestForRawResponseAsync(HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary`2 headers, CancellationToken token)
   at Docker.DotNet.Models.StreamUtil.MonitorResponseForMessagesAsync[T](Task`1 responseTask, DockerClient client, CancellationToken cancel, IProgress`1 progress)
   at DotNet.Testcontainers.Clients.DockerImageOperations.CreateAsync(IImage image, IDockerRegistryAuthenticationConfiguration dockerRegistryAuthConfig, CancellationToken ct)
   at DotNet.Testcontainers.Clients.TestcontainersClient.PullImageAsync(IImage image, CancellationToken ct)
   at DotNet.Testcontainers.Clients.TestcontainersClient.RunAsync(IContainerConfiguration configuration, CancellationToken ct)
   at DotNet.Testcontainers.Containers.DockerContainer.UnsafeCreateAsync(CancellationToken ct)
   at DotNet.Testcontainers.Containers.DockerContainer.StartAsync(CancellationToken ct)
   at DotNet.Testcontainers.Containers.ResourceReaper.GetAndStartNewAsync(Guid sessionId, IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, IImage resourceReaperImage, IMount dockerSocket, Boolean requiresPrivilegedMode, TimeSpan initTimeout, CancellationToken ct)
   at DotNet.Testcontainers.Containers.ResourceReaper.GetAndStartNewAsync(Guid sessionId, IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, IImage resourceReaperImage, IMount dockerSocket, Boolean requiresPrivilegedMode, TimeSpan initTimeout, CancellationToken ct)
   at DotNet.Testcontainers.Containers.ResourceReaper.GetAndStartDefaultAsync(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, Boolean isWindowsEngineEnabled, CancellationToken ct)
   at DotNet.Testcontainers.Clients.TestcontainersClient.RunAsync(IContainerConfiguration configuration, CancellationToken ct)
   at DotNet.Testcontainers.Containers.DockerContainer.UnsafeCreateAsync(CancellationToken ct)
   at DotNet.Testcontainers.Containers.DockerContainer.StartAsync(CancellationToken ct)
   at Xunit.Sdk.TestInvoker`1.<RunAsync>b__47_0() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 200
   at Xunit.Sdk.ExceptionAggregator.RunAsync[T](Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 107

I have gone into a terminal and ran "docker login", but that did not fix the issue. I also commented out the "WithWaitStrategy" line, but that did not fix the problem.

Can someone help me with this issue please?

Relevant log output

No response

Additional information

No response

Could you please share the output of docker images? It seems like TC is trying to pull the image because it is not found locally (and you are running it behind a proxy that restricts the connection to https://index.docker.io/v1/).

"docker images" output

REPOSITORY                         TAG         IMAGE ID       CREATED       SIZE
mcr.microsoft.com/dotnet/sdk       6.0         4913d919cdfd   2 weeks ago   740MB
mcr.microsoft.com/dotnet/aspnet    6.0         63bd24373d54   2 weeks ago   208MB
property                           service     75fcb4f3ad34   2 weeks ago   239MB
mcr.microsoft.com/dotnet/sdk       <none>      a99f36fdc147   3 weeks ago   740MB
mcr.microsoft.com/dotnet/aspnet    <none>      0fa00441382d   5 weeks ago   208MB
mcr.microsoft.com/dotnet/samples   aspnetapp   b3b1188392e7   5 weeks ago   115MB

We are using a proxy, it's a work network. Out of curiosity I opened a web browser and navigated to "https://index.docker.io/v1/" which returns a 404 page. Not sure if that means the url is incorrect, or maybe me accessing it like that is not correct.

Ah, this makes sense (although we should include the actual image in the Docker.DotNet exception). TC tries to pull Ryuk, our Resource Reaper image, to clean up remaining test resources. Can you try to pull the image manual:

docker pull testcontainers/ryuk:0.5.1

You can override the Docker.DotNet client properties, but I have not tested it with proxy settings yet. All the proxies I am behind allow access to the Docker Hub - AFAIK.

PS C:\src\TestContainerStuff> docker pull testcontainers/ryuk:0.5.1
Error response from daemon: Please run 'docker login'

Yeah looks blocked to me.

@HofmeisterAn Is this a case of getting a url whitelisted, or do I need to configure the unit test in order to get this to work?

I have looked into the Docker.DotNet sources, and it seems that Docker.DotNet takes into account the WebRequest.DefaultWebProxy property. I am not very familiar with this configuration. You can try to configure the default proxy before creating any resources; perhaps that helps.

Do you use a private Docker registry, either as a cache or a proxy? It is possible that the private Docker registry is configured to pull images from the upstream registries. In that case, you can utilize the TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX configuration to automatically prepend the private Docker registry to the image.

$env:TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX="docker.example.internal"

This will pull the images from you private Docker registry. It will change the image to

docker.example.internal/testcontainers/ryuk:0.5.1

Have you been able to configure the proxy? I do not think this issue is related to Testcontainers. Do you mind if we close it? If you need further assistance, please let me know.

Unfortunately I haven't yet been able to configure the proxy, as other work commitments have taken priority. But I've seen examples of how to configure the proxy, so I just need the proxy details from our IT dept and give it a try.

However, as you point out, this is not a Testcontainers issue. I will close this issue.

Thank you for your help.

@HofmeisterAn I found the problem.

I needed to docker logout and then docker login but to use my Docker Hub username, and not my email address.

I got the idea from this StackOverflow answer

After logging in that way, I was able to pull the image docker.example.internal/testcontainers/ryuk:0.5.1, which in turn fixed the issue with my unit test.

Thanks. Interesting. No proxy involved? Otherwise the Docker.DotNet error message is quite misleading.