Docker:Golang WebApp和Postgres服务器之间的连接被拒绝

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?

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).