Casdoor Local Deploy
Setting up Casdoor and PostgreSQL with Docker Compose
Introduction
This documentation outlines the steps taken to set up Casdoor, an open-source OAuth 2.0 and OIDC identity provider, using Docker Compose. The setup includes deploying the Casdoor Docker image and configuring it to use a PostgreSQL database. Additionally, a JSON file is generated to provide a sample initial configuration for organizations, applications, roles, and users.
Prerequisites
- Docker installed on the host machine
Steps to Set Up Casdoor
1. Create Docker Compose File
Create a docker-compose.yml
file with the following content:
version: '3.1'
services:
casdoor:
restart: always
image: casbin/casdoor
entrypoint: /bin/sh -c './server --createDatabase=true'
ports:
- '8000:8000'
depends_on:
- db
environment:
RUNNING_IN_DOCKER: 'true'
volumes:
- ./conf:/conf/
- ./conf/init_data.json:/init_data.json
db:
restart: always
image: postgres
platform: linux/amd64
ports:
- '5432:5432'
environment:
POSTGRES_PASSWORD: supersecretpassword
volumes:
- ./postgres:/var/lib/postgresql/data
2. Create Config File
Create a app.conf
file inside a config
directory with the appropriate connection settings to the PostgreSQL database:
appname = casdoor
httpport = 8000
runmode = dev
copyrequestbody = true
driverName = postgres
dataSourceName = "user=username password=mypassword host=postgres_host port=5432 sslmode=disable dbname=casdoor"
dbName = casdoor
tableNamePrefix =
showSql = false
redisEndpoint =
defaultStorageProvider =
isCloudIntranet = false
authState = "casdoor"
socks5Proxy = "127.0.0.1:10808"
verificationCodeTimeout = 10
initScore = 0
logPostOnly = true
isUsernameLowered = false
origin =
originFrontend =
staticBaseUrl = "https://cdn.casbin.org"
isDemoMode = false
batchSize = 100
enableGzip = true
ldapServerPort = 389
radiusServerPort = 1812
radiusSecret = "secret"
quota = {"organization": -1, "user": -1, "application": -1, "provider": -1}
logConfig = {"filename": "logs/casdoor.log", "maxdays":99999, "perm":"0770"}
initDataFile = "./init_data.json"
frontendBaseDir = "../casdoor"
Replace postgres_host
, username
, and mypassword
with your PostgreSQL database hostname, username, and password, respectively.
3. Generate Initial Configuration JSON File
Create a init_data.json
file with the sample initial configuration for organizations, applications, roles, and users:
{
...
"organizations": [
{
"name": "ExampleOrg",
"display_name": "Example Organization",
"description": "Sample organization"
}
],
"applications": [
{
"name": "example-app",
"display_name": "Example App",
"description": "Sample application",
"organization_name": "ExampleOrg"
}
],
"roles": [
{
"name": "admin",
"display_name": "Administrator",
"description": "Admin role",
"organization_name": "ExampleOrg",
"application_name": "example-app"
}
],
"users": [
{
"username": "admin@example.com",
"password": "password",
"email": "admin@example.com",
"phone": "",
"display_name": "Admin User",
"organization_name": "ExampleOrg",
"application_name": "example-app",
"role_name": "admin"
}
]
...
}
4. Run Docker Compose
Navigate to the directory containing the docker-compose.yml
file and run the following command to start the Casdoor and PostgreSQL containers:
docker-compose up -d
Conclusion
You have successfully set up Casdoor using Docker Compose with PostgreSQL as the database and initialized it with a sample initial configuration for organizations, applications, roles, and users. You can now access Casdoor at http://localhost:8000
and log in using the admin user credentials specified in the init_data.json
file.