本文介绍了mysql容器拒绝Docker Gogs连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置本地git存储库时遇到一些麻烦。我是Docker的新手,因此问题可能很幼稚,但仍然找不到。

I have some trouble with setting my local git repository. I am new to docker, so the problem may be naive but I still can't find it.

所以我的想法是:
我想用gogs(gogs / gogs映像)创建一个容器,并将其连接到mysql容器。

So my idea is: I wanted to create a container with gogs (gogs/gogs image) and connect it to mysql container.

为此,我创建了docker-compose.yml文件。

To do so I have created docker-compose.yml file.

version: '3'
services:
  db:
    image: mysql
    ports:
      - "10023:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root!
  ui:
    image: phpmyadmin/phpmyadmin
    ports:
      - "8989:80"
    links:
      - db:mysql
  repo:
    image: gogs/gogs
    ports:
      - "10022:22"
      - "10080:3000"
    volumes:
      - /tmp/gogs:/data gogs/gogs
    links:
      - db:mysql

我都将phpmyadmin放在我的设置中,这样我就可以轻松测试mysql是否启动并响应其他容器。

I all put phpmyadmin in my setup, this way I can easily test if mysql is up and respond to other containers.

不幸的是,这种环境无法正常工作,当进入localhost:10080上的gogs安装页面并尝试创建新的存储库时,它说tcp连接已被拒绝。这是错误消息的输出:

Sadly this environment does't work, when get to gogs install page on localhost:10080 and try to create a new repo, it says that tcp connection has been refused. This is the output of the error message:

dial tcp 127.0.0.1:10023: getsockopt: connection refused

这很奇怪,因为我可以通过phpmyadmin访问mysql容器。我还能够创建gogs数据库。

This is strange, because I can access to mysql container through phpmyadmin. I also was able to create gogs database.

有人以前有这个问题吗?

Do anybody had this issue before?

推荐答案

不要在容器内部使用localhost或127.0.0.1,请使用docker-compose中定义的服务名称。

Don't use localhost or 127.0.0.1 from inside the container, use the service name as defined in your docker-compose.

拨号tcp db:10023

这篇关于mysql容器拒绝Docker Gogs连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-15 11:07