Golang连接到Docker连接到我的SQL Docker时出现getsockopt错误:连接被拒绝。

huangapple go评论141阅读模式
英文:

Golang connect to docker connect to my sql docker getsockopt: connection refused

问题

我正在努力设置我的Golang和Docker环境,但感到非常困惑。我正在使用Docker Compose,它似乎可以成功构建两个镜像,但当我尝试运行Golang操作时,出现了错误。

英文:

I am loosing my mind trying to set up my golang and docker env. I am using docker compose which seems to book both images fine but when I try run and go lang operations I get an error.

答案1

得分: 0

你的yaml文件中的缩进很重要,你的mysql行应该与你的app行对齐。

app:部分下面添加以下内容:

links:
  - mysql

这样它就知道连接这两个部分了。

在这里https://github.com/gpuenteallott/golang-mysql-docker-setup/blob/master/docker-compose.yml可以找到一个很好的工作示例。

英文:

The spacing in your yaml file is important, your mysql line should line up with your app line.

You have to add a

links:
  - mysql

line in under your app: section so it knows to connect the two.

Look here https://github.com/gpuenteallott/golang-mysql-docker-setup/blob/master/docker-compose.yml for a decent working example.

huangapple
  • 本文由 发表于 2017年5月4日 00:34:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/43765581.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定