Home > Enterprise >  docker compose - unauthorized: unauthorized to access repository
docker compose - unauthorized: unauthorized to access repository

Time:12-31

I'm having issues using docker compose with private repositories.

Looking for similar issues i can't get --verbose to give any meaningful output, to help debugging the issue.

When i use docker compose to pull images from a private registry i receive the error:

"Error response from daemon: unauthorized: unauthorized to access repository: myrepo/myservice, action: pull: unauthorized to access repository: myrepo/myservice, action: pull"

I've made sure to run the docker login command, before running docker compose up.

If i run docker pull on the image described in the compose file, the image is downloaded as expected, but running docker compose up fails.

i'm using docker for windows. docker compose version 2.13. docker version:

PS C:\Users\kov\source\repos\localsetup> docker version
Client:
 Cloud integration: v1.0.29
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:08:16 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.15.0 (93002)
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:00:19 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.10
  GitCommit:        770bd0108c32f3fb5c73ae1264f7e503fe7b2661
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

my docker compose file:

services:
  appRestApiEndpoint:
    image: myregistry.io/repo/app-rest-api-endpoint
    container_name: my-service
    ports:
      - 5000:80
    networks:
      - backend
    environment:
      - ASPNETCORE_ENVIRONMENT=myEnvVariable
  
networks:
  backend:

CodePudding user response:

I can provide you with the following solution / workaround, though I'm not sure if this is the "wanted" behavior of docker-compose or a bug; see the link I mentioned above.

Create the following config file

  • For Linux I know the file is: ~/.docker/config.json
  • For Windows it might be similar to C:\Users\<username>\.docker\config.json

Example for Docker Hub registry:

{
    "auths": {
        "https://index.docker.io/v1/": {
            "auth": "<auth-string>"
        }
    }
}

<auth-string> is the base64-encoded string: <docker-loginname>:<auth-token>. The <auth-token> can be generated by logging into docker hub.

Example for Harbor docker registry:

{
    "auths": {
        "<harbor-url": {
            "auth": "<auth-string>"
        }
    }
}

<auth-string> is base64(<loginname>:<password>)

  • Related