Running locally with Docker
How to run locally with Docker.
Authgear is available as a Docker image. It depends on PostgreSQL and Redis. To run it locally, the simplest way is to use docker-compose.

Create the project directory

Let's get started with creating a new directory.
1
mkdir myapp
2
cd myapp
Copied!

Create authgear.yaml and authgear.secrets.yaml

First, we need to create authgear.yaml and authgear.secrets.yaml. Authgear itself is a CLI program capable of generating a minimal configuration file.
Run the following command to generate a minimal authgear.yaml:
1
docker run --rm -it -w "/work" -v "$PWD:/work" quay.io/theauthgear/authgear-server authgear init config
Copied!
authgear.yaml is generated in your working directory.
Run the following command to generate a minimal authgear.secrets.yaml:
1
docker run --rm -it -w "/work" -v "$PWD:/work" quay.io/theauthgear/authgear-server authgear init secrets
Copied!
authgear.secrets.yaml is now generated in your working directory.

Create docker-compose.yaml

The next step is to create docker-compose.yaml to setup PostgreSQL, Redis, and Authgear.
You can start with the following docker-compose.yaml:
1
version: "3"
2
services:
3
db:
4
image: postgres:12.3
5
volumes:
6
- db_data:/var/lib/postgresql/data
7
environment:
8
POSTGRES_USER: "postgres"
9
POSTGRES_PASSWORD: "postgres"
10
ports:
11
- "5432:5432"
12
13
redis:
14
image: redis:5.0
15
volumes:
16
- redis_data:/data
17
ports:
18
- "6379:6379"
19
20
authgear:
21
# Remember to replace the latest tag with the exact version you would like to use!
22
image: quay.io/theauthgear/authgear-server:latest
23
volumes:
24
- ./authgear.yaml:/app/authgear.yaml
25
- ./authgear.secrets.yaml:/app/authgear.secrets.yaml
26
environment:
27
DEV_MODE: "true"
28
LOG_LEVEL: "debug"
29
ports:
30
- "3000:3000"
31
32
volumes:
33
redis_data:
34
driver: local
35
db_data:
36
driver: local
Copied!

Edit authgear.secrets.yaml

The three services run in the same network. We have to ensure Authgear can connect to PostgreSQL and Redis.
Check authgear.secrets.yaml and see if it looks like the following:
1
secrets:
2
- key: db
3
data:
4
database_schema: public
5
database_url: postgres://postgres:[email protected]:5432/postgres?sslmode=disable
6
- key: redis
7
data:
8
host: redis
9
port: 6379
10
# Other entries that are randomly generated.
11
# They are not listed here because they will be different.
Copied!

Start PostgreSQL and Redis

Authgear depends on them so they have to be started first.
1
docker-compose up -d db redis
Copied!

Run database migration

Run the database migration:
1
docker-compose run --rm authgear authgear migrate up
Copied!

Get it running

Run everything with:
1
docker-compose up
Copied!

Verify everything is working

Visit http://localhost:3000 and try signing up as a new user!
Last modified 1yr ago