#Service binding issue

1 messages ยท Page 1 of 1 (latest)

strange coral
#

I feel like I'm hitting a bug or missing something obvious. Running the below based on the service example in the cookbook and... no dice.

func (m *Example) Postgres() *dagger.Service {
    return dag.Container().
        From("postgres").
        WithEnvVariable("POSTGRES_USER", "root").
        WithEnvVariable("POSTGRES_PASSWORD", "secret").
        // WithMountedCache("/var/lib/postgresql/data", dag.CacheVolume("postgres")).
        WithExposedPort(5432).
        AsService()
}

func (m *Example) Psql() *dagger.Container {
    return dag.Container().
        From("postgres").
        WithServiceBinding("db", m.Postgres()).
        WithExec([]string{"sh", "-c", "sleep 15 && psql -h db -U root"})
}
$ dagger call psql
...
โœ˜ Container.sync: ContainerID! 16.6s
! process "sh -c sleep 15 && psql -h db -U root" did not complete successfully: exit code: 2

Error: invalid selection for command "psql": response from query: input: container.from.withServiceBinding.withExec.sync resolve: process "sh -c sleep 15 && psql -h db -U root" did not complete successfully: exit code: 2

Stderr:
psql: error: connection to server at "db" (0.0.0.0), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?
round pecan
#

Seeing 0.0.0.0 is a bit strange in the error. It should be resolving to the Postgres hostname

strange coral
#

Yeah that's what I figured too.

$ dagger version
dagger v0.12.3 (registry.dagger.io/engine) darwin/arm64

M3 MacBook Air, docker via colima.

round pecan
#

this is what I'm currently getting

127.0.0.1       localhost buildkitsandbox
::1     localhost ip6-localhost ip6-loopback

10.87.0.31      db
round pecan
#

^ there you can see that db is effectively assigned to the service ip

strange coral
#

Hyup, that'll do it ๐Ÿ˜…

cat /etc/hosts
127.0.0.1       localhost rqhag0dclk31q.i2d2dj1ja4e6c.dagger.local
::1     localhost ip6-localhost ip6-loopback

0.0.0.0 db
round pecan
#

Silently cc'ing @wheat arrow