一次安装步骤(使用docker-compose)
version: '3'services:server:image: postgrest/postgrestports:- "3000:3000"links:- db:dbenvironment:PGRST_DB_URI: postgres://app_user:password@db:5432/app_dbPGRST_DB_SCHEMA: publicPGRST_DB_ANON_ROLE: app_user #In production this role should not be the same as the one used for the connectionPGRST_SERVER_PROXY_URI: "http://127.0.0.1:3000"depends_on:- dbdb:image: postgresports:- "5432:5432"environment:POSTGRES_DB: app_dbPOSTGRES_USER: app_userPOSTGRES_PASSWORD: password# Uncomment this if you want to persist the data.volumes:- "~/postgrest/pgdata:/var/lib/postgresql/data"
docker-compose -up 运行
分开步骤
docker安装postgresql
# 安装并后台运行postgresqlsudo docker run --name postgres -p 5432:5432 \-e POSTGRES_PASSWORD=123456 \-d postgres# 进入postgressudo docker exec -it postgres /bin/bash
进入数据库,创建对应模式和表
sudo su - postgrespsql# 创建模式create schema api;# 创建表create table api.todos (id serial primary key,done boolean not null default false,task text not null,due timestamptz);# 写入2条数据insert into api.todos (task) values ('finish tutorial 0'), ('pat self on back');
创建访问模式的角色
create role web_anon nologin;grant usage on schema api to web_anon;grant select on api.todos to web_anon;create role authenticator noinherit login password '123456';grant web_anon to authenticator;
docker安装postgrest
sudo docker run --name postgrest -p 3000:3000 \-v ~/config:/etc/etc/postgrest/config-d postgrest/postgrest:latest
手动安装postgrest
cd ~wget https://github.com/PostgREST/postgrest/releases/download/v7.0.1/postgrest-v7.0.1-linux-x64-static.tar.xztar xJf postgrest-v7.0.1-linux-x64-static.tar.xzmv postgrest /usr/local/bin
如果提示wget不存在,运行下面命令安装wget apt update && apt install -y wget
创建postgrest配置文件
sudo mkdir /etc/postgrestsudo vi /etc/postgrest/config### 配置文件内容db-uri = "postgres://authenticator:123456@localhost:5432/postgres"db-schema = "api"db-anon-role = "web_anon"#### 运行postgrest/usr/local/bin/postgrest /etc/postgrest/config# 访问 http://localhost:3000/todoscurl http://localhost:3000/todos
如果提示vi不存在,则运行如下命令 apt install -y vim

