authorizerdev / authorizer

Your data, your control. Fully open source, authentication and authorization. No lock-ins. Deployment in Railway in 120 seconds || Spin a docker image as a micro-service in your infra. Built in login page and Admin panel out of the box.
https://authorizer.dev
MIT License
1.64k stars 166 forks source link

Docker Authorizer is not connecting with localhost db #384

Closed bete7512 closed 1 year ago

bete7512 commented 1 year ago

Docker Authorizer doesnot connecting with my local Postgres but it connects to container db sudo docker run -p 8081:8080 --env-file .env -d --restart unless-stopped --name authorizer lakhansamani/authorizer:1.1.46

lakhansamani commented 1 year ago

@bete7512 it is docker networking issue, I used host.docker.internal network to connect postgres running locally and that worked

Example Started postgres using docker:

docker run --name pg -e POSTGRES_PASSWORD=admin -p 5432:5432 -d postgres

Then started authorizer

docker run --name authorizer --network=host -p 8080:8080 lakhansamani/authorizer:latest ./build/server --database_type=postgres --database_url=postgresql://postgres:admin@host.docker.internal:5432/postgres
lakhansamani commented 1 year ago

Another quick way to run this is using docker-compose.

version: '3.3'
services:
  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: 'admin'
    volumes:
      - db:/var/lib/postgresql/data
  authorizer:
    image: lakhansamani/authorizer
    restart: always
    ports:
      - '8080:8080'
    depends_on:
      - db
    environment:
      DATABASE_TYPE: "postgres"
      DATABASE_URL: "postgres://postgres:admin@db/postgres"
volumes:
  db:
    driver: local

So, it's not a bug related to the authorizer but something to do with the docker setup. Thanks for sharing it

yescine commented 1 year ago

@lakhansamani can you add this docker-compose and a full example with Redis and all default ENV variables in the official documentation ! (We always prefer one-command solution :) )

lakhansamani commented 1 year ago

Sure @yescine can add this to doc 👍