In your api containers environment declaration, try DSN: "db://postgres:postgres@db:5432/postgres?sslmode=disable". This will connect directly to the db container. 127.0.0.1 is the localhost inside your go container, not your host machines localhost.
apicontainers environment declaration, tryDSN: "db://postgres:postgres@db:5432/postgres?sslmode=disable". This will connect directly to thedbcontainer.127.0.0.1is the localhost inside your go container, not your host machines localhost.panic: dial tcp [::1]:5432: getsockopt: connection refused