netlify / gotrue

An SWT based API for managing users and issuing SWT tokens.
https://www.gotrueapi.org
MIT License
3.84k stars 285 forks source link

Docker container database connection error #235

Closed sakonn closed 4 years ago

sakonn commented 4 years ago

- Do you want to request a feature or report a bug? Report a bug

- What is the current behavior? I am not able to connect to db from the docker container.

- If the current behavior is a bug, please provide the steps to reproduce. I have cloned the repository and started it by following docker compose file:

version: '3'

services:
  gotrue:
    container_name: go
    build: .
    env_file: .env
    depends_on:
      - mariadb
    ports:
      - 8081:8081

  mariadb:
    container_name: db
    image: mariadb
    environment:
        MYSQL_DATABASE: gotrue_development
        MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    restart: always
    volumes:
      - gotrue_mariadb_data:/var/lib/mysql
    ports:
      - 3306:3306

  phpmyadmin:
    container_name: admin
    image: 'bitnami/phpmyadmin'
    restart: always
    depends_on:
      - mariadb
    ports:
      - '7000:80'
      - '443:443'
    environment: 
      DATABASE_HOST: mariadb

volumes:
  gotrue_mariadb_data:

When I start container I can connect to the url: http://localhost:8081/settings without complications. This is my db configuration:

GOTRUE_DB_DRIVER=mysql
DATABASE_URL='gotrue@tcp(db:3306)/gotrue_development' 

When I try to make request to the database verify/signup.... I get the error level=error msg="500: Database error finding user" component=api error="error finding user: mysql select one: Error 1045: Access denied for user ''gotrue'@'192.168.176.6' (using password: NO)" method=POST path=/signup

Confusing point on this is that phpmyadmin is able to comunicate with databse properly and also when I run gotrue without container (and database in the container) it works fine.

- What is the expected behavior? Being able to connect to database from docker container.

- Please mention your Go version, and operating system version. GO: go version go1.13.8 linux/amd64 OS: Distributor ID: LinuxMint Description: Linux Mint 19.3 Tricia Release: 19.3 Codename: tricia Docker: Docker version 19.03.6, build 369ce74a3c Docker-compose: docker-compose version 1.25.3, build d4d1b42b

Hamzali commented 4 years ago

hello, I have also run into the same problem as you :)

actually it is not about connection or anything else and the main problem is that gotrue does not migrate database when you run it as an API

it uses cobra to manage running database migrations therefor after your compose is running you can manually migrate the database by using

this worked for me :)

Actually this needs to be in the documentation it could be impossible to figure out for someone who does not use GO :)

mheffner commented 4 years ago

Thanks @Hamzali and @sakonn , I've added a note in https://github.com/netlify/gotrue/pull/246