3

I can't connect my Postgres container with my golang webapp container.

i got following error:

panic: dial tcp [::1]:5432: getsockopt: connection refused

My docker compose file:

http://pastebin.com/5LQfn3gy

Any idea how i can fix that?

5
  • you need to change the ports: ports: - "81:82" Commented Feb 2, 2017 at 13:11
  • 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. Commented Feb 2, 2017 at 13:13
  • try to replace this one ports: - "127.0.0.1:5432:5432" to 5432:5432 Commented Feb 2, 2017 at 13:17
  • i have changed 127.0.0.1:5432 to :5432 but now i getting this panic: dial tcp [::1]:5432: getsockopt: connection refused Commented Feb 2, 2017 at 13:20
  • @Donutloop This might be the solution for your problem: stackoverflow.com/a/60366545/516512 Commented Feb 23, 2020 at 20:32

1 Answer 1

0

Since the IP you specified relates to your host and not your docker environment and you're running your app inside docker too, just omit the IP:

ports:
  -5432:5432

So you'd just need to pass the Postgres alias, followed by its port to your go app (either as an env var or a flag).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.