Problem with docker-compose to encapsulate Gogs with MySQL


#1

Hello,
I am trying to encapsulate Gogs with MySQL with docker-compose.
I have the following problem:
-When I run the containers separately (with $docker run) I can install the database correctly.
-Otherwise, when I mix the two containers in a docker-compose.yml, it notice the following error in the first-time install:

Database setting is not correct: dial tcp 127.0.0.1:3306: getsockopt: connection refused

I am running the 1.18 version of docker compose in a Ubuntu 16.04 VM. The Gogs version is the :latest

My docker-compose.yml:

version: '3.4'

services:

  mysql:
    image: mysql
    ports:
      - 3306:3306
    volumes:
      - ~/workspace/db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=rootpass
      - MYSQL_DATABASE=gogs
      - MYSQL_USER=user
      - MYSQL_PASSWORD=pass
  gogs:
      image: gogs/gogs
      ports:
        - 10080:3000
        - "10022:22"
      links:
        - mysql
      volumes:
        - ~/workspace/gogs:/data

Note: I use “10022:22” to avoid that error:

ERROR: for documents_gogs_1 Cannot create container for service gogs: invalid port specification: "601342"

Thanks


#2

Change the host to mysql:3306 instead of 127.0.0.1

Screenshot_2017-12-23_00-32-06

You should use networks in favor of links, because links are deprecated. Also a good idea to define dependencies and a restart policy.

version: '3'

services:

  mysql:
    image: mysql
    restart: always
    ports:
      - 3306:3306
    networks:
      - gogs-backend
    volumes:
      - ~/workspace/db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=rootpass
      - MYSQL_DATABASE=gogs
      - MYSQL_USER=user
      - MYSQL_PASSWORD=pass

  gogs:
      image: gogs/gogs
      depends_on:
        - mysql
      restart: always
      ports:
        - 10080:3000
        - "10022:22"
      networks:
        - gogs-backend
      volumes:
        - ~/workspace/gogs:/data

networks:
  gogs-backend:
    driver: bridge

#4

Thanks Matt!
It got it working with the changes you suggested.


#5

Good to hear :slightly_smiling_face: