dotnet / sdk-container-builds

Libraries and build tooling to create container images from .NET projects using MSBuild

Home Page:https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Having trouble with DockerHub auth

richlander opened this issue · comments

This is what I'm doing. Is the credsStore the problem? This is macOS. However, I'm having similar troubles with Linux which have the actual key listed.

I used these docs to help me: https://github.com/dotnet/sdk-container-builds/blob/main/docs/RegistryAuthentication.md

rich@Richs-Air aspnetapp % cat ~/.docker/config.json 
{
	"auths": {
		"registry-1.docker.io": {}
	},
	"credsStore": "osxkeychain"
rich@Richs-Air aspnetapp % docker push registry-1.docker.io/richlander/foo
Using default tag: latest
The push refers to repository [registry-1.docker.io/richlander/foo]
b8626f0b12c3: Pushed 
62a23db67138: Pushed 
ca1220d04e84: Pushed 
594cfb823b79: Pushed 
ccee82bd4c2b: Pushed 
b77e3d3557f9: Pushed 
973204c0e25a: Pushed 
8450f74cd36b: Pushed 
latest: digest: sha256:3c170d66a615f5bd2d0d8bd7253e819e07520c3dbed057f7599e3d65a38e2dcb size: 1997
rich@Richs-Air aspnetapp % cd aspnetapp                                                 

rich@Richs-Air aspnetapp % dotnet publish /p:PublishProfile=DefaultContainer /p:ContainerRegistry=registry-1.docker.io

MSBuild version 17.7.0+5785ed5c2 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
/usr/local/share/dotnet/sdk/8.0.100-preview.6.23330.14/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(314,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/aspnetapp.csproj]
  aspnetapp -> /Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/bin/Release/net8.0/aspnetapp.dll
  aspnetapp -> /Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/bin/Release/net8.0/publish/
  Building image 'aspnetapp' with tags latest on top of base image mcr.microsoft.com/dotnet/aspnet:8.0.0-preview.6
  Uploading layer sha256:90524f7dc01b4ce9b387992acc6cbdbcc2a9ee8c6addfd632429ca06ea18751e to registry-1.docker.io
  Uploading layer sha256:ebe55b10ad99f72afdea8c2e9ffc5275f4be4eaa6fc036a9df80646095a29103 to registry-1.docker.io
  Uploading layer sha256:7cf7f3f2109196747b000601ac887a072dd972273dcda5f8cb6bbcd02aa6fb13 to registry-1.docker.io
  Uploading layer sha256:a2b577495cbdf53b63c2245e26c70cfd751625b762017a7cf266bcfa11a1e4aa to registry-1.docker.io
  Uploading layer sha256:55b307c388065fd08c4774bbdcbebb52073bdfba20c0179029d2881960700e97 to registry-1.docker.io
  Uploading layer sha256:7ee86b5ee4ce95ccb1f837e5b8baa206e13c3fb1e3956920e21015db455af8be to registry-1.docker.io
  Uploading layer sha256:f22582a9a24f0aade222cc75db1ebba27251885e1353710f867ef9c0f9941856 to registry-1.docker.io
/usr/local/share/dotnet/sdk/8.0.100-preview.6.23330.14/Containers/build/Microsoft.NET.Build.Containers.targets(201,5): error CONTAINER1013: Failed to push to the output registry: CONTAINER1001: Failed to upload blob to POST https://registry-1.docker.io/v2/aspnetapp/blobs/uploads/; received Unauthorized with detail docker-distribution-api-version: registry/2.0 [/Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/aspnetapp.csproj]
/usr/local/share/dotnet/sdk/8.0.100-preview.6.23330.14/Containers/build/Microsoft.NET.Build.Containers.targets(201,5): error CONTAINER1013: WWW-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:aspnetapp:pull,push",error="insufficient_scope" [/Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/aspnetapp.csproj]
/usr/local/share/dotnet/sdk/8.0.100-preview.6.23330.14/Containers/build/Microsoft.NET.Build.Containers.targets(201,5): error CONTAINER1013: Date: Sat, 29 Jul 2023 00:10:15 GMT [/Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/aspnetapp.csproj]
/usr/local/share/dotnet/sdk/8.0.100-preview.6.23330.14/Containers/build/Microsoft.NET.Build.Containers.targets(201,5): error CONTAINER1013: Strict-Transport-Security: max-age=31536000 [/Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/aspnetapp.csproj]
/usr/local/share/dotnet/sdk/8.0.100-preview.6.23330.14/Containers/build/Microsoft.NET.Build.Containers.targets(201,5): error CONTAINER1013:  [/Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/aspnetapp.csproj]
/usr/local/share/dotnet/sdk/8.0.100-preview.6.23330.14/Containers/build/Microsoft.NET.Build.Containers.targets(201,5): error CONTAINER1013: {"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"aspnetapp","Action":"pull"},{"Type":"repository","Class":"","Name":"aspnetapp","Action":"push"}]}]} [/Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/aspnetapp.csproj]
/usr/local/share/dotnet/sdk/8.0.100-preview.6.23330.14/Containers/build/Microsoft.NET.Build.Containers.targets(201,5): error CONTAINER1013: . [/Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/aspnetapp.csproj]

On Linux, my config.json looks like this:

$ cat ~/.docker/config.json 
{
	"auths": {
		"registry-1.docker.io": {
			"auth": "-elided-"
		}
	}
}

This should work better with preview 7.

You can use docker.io instead of registry-1.docker.io as the ContainerRegistry.

And when using the docker login command without any additional arguments, that should use a key of https://index.docker.io/v1/ in the config.json file.
The preview 7 SDK will use those credentials for the docker.io registry.

cc @baronfel

Rich and I spoke about this a bit offline - yes the reuse of docker credentials will get better, but the real issue is that he didn't include his user namespace in the image repository. We didn't doc this explicitly in the configuration docs for ContainerRepository, and the error message doesn't help guide users to a resolution.

I tried ContainerRepository and then that sort of worked. I got a ton of these:

Encountered a SocketException with message "Broken pipe". Pausing before retry.

Which ended in:

/usr/local/share/dotnet/sdk/8.0.100-preview.6.23330.14/Containers/build/Microsoft.NET.Build.Containers.targets(201,5): error CONTAINER1013: Failed to push to the output registry: CONTAINER1006: Too many retries, stopping. [/Users/rich/git/dotnet-docker/samples/aspnetapp/aspnetapp/aspnetapp.csproj]

I'll try again later with the suggestion from @tmds.

Working now!

My test:

$ docker login -u richlander
$ dotnet publish /p:PublishProfile=DefaultContainer /p:ContainerBaseImage=mcr.microsoft.com/dotnet/aspnet:8.0-preview-jammy-chiseled /p:ContainerRegistry=docker.io /p:ContainerRepository=richlander/foo

Thanks for the help!

For anyone looking at this later, I use Docker PATs for my password since I have 2FA enabled. Works great.

https://docs.docker.com/docker-hub/access-tokens/