#Docker registry credentials

1 messages ยท Page 1 of 1 (latest)

balmy brook
#

How do I pass credentials to a registry when pulling? Naively I would expect container { from } to have an optional auth argument, but that doesn't exist. Is it not implemented, or implemented in another way?

timid forum
#

Hi, the only solution i found is to execute a docker login in the "host machine"

muted quarry
#

Exactly

balmy brook
#

OK, it would be nice to get the same functionality as with 0.2 engine, where credentials can be passed directly in the code for each push/pull call. I'm guessing that's planned

iron grove
past moth
#

I'm in a weird situation where I can't do a "docker login" because my the remote machine(where buildkit is running ) doesn't have docker and neither does the container. Also, this isn't going to be one-time operation for my use-case as my pipeline needs to push to different container repos based off the parameters.

I'm looking at writing ~/docker/config.json in the container to see if that works.

balmy brook
past moth
#

Yeah, it's mostly something I'm in control of.

type DockerConfig struct {
    Auths map[string]AuthConfig `json:"auths"`
}

type AuthConfig struct {
    Auth string `json:"auth"`
    Email string `json:"email"`
}


func NewDockerConfig(username, password, email string) DockerConfig {
    authStr := fmt.Sprintf("%s:%s", username, password)
    authBytes := []byte(authStr)
    encodedAuth := base64.StdEncoding.EncodeToString(authBytes)

    return DockerConfig{
        Auths: map[string]AuthConfig{
            "https://index.docker.io/v1/": {
                Auth: encodedAuth,
                Email: email,
            },
        },
    }
}

So the pipeline will accept those args

balmy brook
#

Really it should be a username / secret argument in the API, like in the CUE API

past moth
#

I'm struggling a bit mounting files into container. Is there an example?
I'm on Dagger v0.3.1

muted quarry
past moth
#

Go SDK

muted quarry
past moth
#

Thank you so much ๐Ÿ™‚

muted quarry
#

In this example, we mount from one container to another. What do you intend to mount ? From countainer to container or from host to container ?

#

To load a dir from host, then mount it to a container.
There is this example : https://pkg.go.dev/dagger.io/dagger#Host. Then, you can follow with a mountedDirectory of the container, following the first link

#

Do you think it's helpful or do you still want a full example ?

past moth
#

Let me play around and I'll get back to you . Thank you

past moth
#

Got it to work! Thanks again @muted quarry ๐Ÿ˜„

grizzled heart
#

From the content of this thread, I realized that docker login must be done outside of dagger.
For example, when publishing a container from github actions to the github container registry, is this the right way to do it?

Or is there a simpler way?

-> github actions sample

jobs:
  dagger:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io --username ${{ github.actor }} --password-stdin
      - uses: dagger/dagger-for-github@v3
        with:
          cmds: do check
muted quarry