Self-hosting gotrue

has anyone managed to successfully run a selfhosted gotrue instance?

i have cloned the gotrue repo, and added the following docker-compose.yml and env files, ran the migrations successfully (i think), but don’t get a response when trying http://localhost:8081/settings:

# docker-compose.yml
version: "3.8"

services:
  app:
    build: .
    restart: unless-stopped
    depends_on:
      - db
    env_file:
      - gotrue.env
    ports:
      - 8081:8081

  db:
    image: mysql:5.7
    restart: unless-stopped
    env_file:
      - db.env
    volumes:
      - db:/var/lib/mysql

volumes:
  db:
# db.env
MYSQL_ROOT_PASSWORD=gotrue
MYSQL_DATABASE=gotrue
MYSQL_USER=gotrue
MYSQL_PASSWORD=gotrue
# gotrue.env
GOTRUE_DB_DRIVER=mysql
DATABASE_URL="gotrue:gotrue@tcp(db:3306)/gotrue?parseTime=true&multiStatements=true"
GOTRUE_API_HOST=localhost
PORT=8081
GOTRUE_SITE_URL=http://localhost:3000
GOTRUE_JWT_SECRET=s3cr3t
GOTRUE_JWT_EXP=3600
GOTRUE_OPERATOR_TOKEN=s3cr3t
GOTRUE_LOG_LEVEL=debug

i have run docker-compose run --rm app gotrue migrate for the migrations, which seems to have worked. docker logs gotrue_app_1 does not show anything useful, even with log level debug.

when trying to reach http://localhost:8081/settings i get “Connection reset by peer”.

Hey @stefanprobst! :wave:t2:

I’m pretty familiar with GoTrue but haven’t actually run a self-hosted instance myself. At the outset, I do see that you have

GOTRUE_SITE_URL=http://localhost:3000

but your docker compose appears to be looking for 8081? I might have some wires confused there, but just wanted to check just in case.

Let me know if that helps!


Jon

hi jon,

if i’m reading the docs correctly, the gotrue host is set with GOTRUE_API_HOST and PORT, while GOTRUE_SITE_URL should point to the client application (which in my case runs on port 3000 locally).

The gotrue repo e.g. has these lines in example.env:

GOTRUE_API_HOST=localhost
PORT=9999
GOTRUE_SITE_URL=https://my-jam-site.example.com

Ah I see. I forgot the GOTRUE_SITE_URL is just for emails and other callbacks, not for real-time API behavior.

Oddly enough, the code example in the docs shows them using the key GOTRUE_API_HOST while the actual doc paragraph for that variable reads as just API_HOST. Strange, but have you tried switching the ENV var key from GOTRUE_API_HOST to API_HOST?


Jon

Just popped open the GoTrue code again, and, while I haven’t run it myself to verify, you should be getting a log message similar to GoTrue API started on: localhost:8081 if the server began running correctly. Seems like there may be trouble in starting up if you’re not getting that message, but not seeing anything in STDOUT / STDERR is strange too :thinking:


Jon

Hi, @stefanprobst. Someone has posted their working configuration for self-hosted gotrue here:

Maybe that example can be a helpful reference here.

yeah the docs are a bit confusing - they state that "Environment variables are prefixed with GOTRUE_" except where explicitly stated otherwise (e.g. PORT) but the actual code examples don’t follow that rule.

hi luke, thanks for the link, i’ll take a look! - the setup is a bit different though since i’m trying to run this with docker.

ok, i think i finally figured this out: things seems to work with GOTRUE_API_HOST=app (instead of localhost)

thanks for sharing that, @stefanprobst! I will see if we can make our docs on this more clear.

thanks! i think an example docker-compose.yml could be helpful - and maybe a quick check of the content of example.env