#Service binding DNS lookup Failed

1 messages · Page 1 of 1 (latest)

visual spindle
#

Hi, I'm trying to use the service binding but it is failling to resolve to the alias
Here the code snippet in go sdk

        registry := client.Container().From("registry:2").WithExec(nil).WithExposedPort(5000)

    _, err = client.Container().
        From("alpine").
        WithServiceBinding("registry", registry).
        WithExec([]string{"apk", "add", "bind-tools"}).
        WithExec([]string{"ping", "registry"}).
        Stdout(ctx)

    // Publish
    ref, err := client.Container().
        From("alpine").
        WithFile("/bin/", bin).
        WithServiceBinding("registry", registry).
        Publish(ctx, "registry:5000/dagger-demo")
    if err != nil {
        return err
    }
    log.Info(ref)

The result :

process \"ping registry\" did not complete successfully: exit code: 1\nStdout:\n\nStderr:\nping: bad address 'registry'

I also reproduce this on playground. https://play.dagger.cloud/playground/r_k0Z9mT_kU
What am i missing ?
Thanks

chrome helm
#

strange. I wonder if ping is not respecting /etc/hosts?

#

the second example definitely won't work unfortunately, since buildkit requires TLS for any non-localhost registry address

visual spindle
#

Yes, i figure out tor the second but yes first one is weird.

chrome helm
#

the ping example seems to work on my machine. I changed it to a ping -c1 so it only pings once rather than forever, but it works without it too

#
func TestContainerPing(t *testing.T) {
    t.Parallel()

    checkNotDisabled(t, engine.ServicesDNSEnvName)

    client, ctx := connect(t)
    defer client.Close()

    registry := client.Container().From("registry:2").WithExec(nil).WithExposedPort(5000)

    _, err := client.Container().
        From("alpine").
        WithServiceBinding("registry", registry).
        WithExec([]string{"apk", "add", "bind-tools"}).
        WithExec([]string{"ping", "-c1", "registry"}).
        Stdout(ctx)
    require.NoError(t, err)
}
visual spindle
#

Ok it's because of the place of WithServiceBinding in the method chain. If you put it after exec it fails

chrome helm
#

oh makes sense. was that a local change?

#

(your example had it right)

visual spindle
#

indeed i might have gotten mixed up with my snippet

#

but now i know 😄

frail shell
#

note that this probably doesnt do what you want since dagger wont push to insecure registries unless its on 127.0.0.1