Search code examples
mysqldockergogs

Docker gogs connection is refused by mysql container


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.

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

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

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

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

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?


Solution

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

    dial tcp db:10023

    docker-compose networking.