This guide assumes that you already have Postgres running and helps you set up the prestd using Docker and connect it to your Postgres database.
In case you’d like to run prestd with a fresh Postgres database, follow this guide to deploy the prestd along with a Postgres instance using Docker Compose.
Create an installation folder called
prestd where you would like your
prestd installation and data storage.
cd (open/join) into the installation folder.
We will use docker to run pREST and connect to an existing database. To simplify the example we leave the authentication module off
1docker run -d -p 3000:3000 \ 2 -e PREST_PG_URL=postgres://username:password@hostname:port/dbname \ 3 -e PREST_DEBUG=true \ 4 prest/prest:v1
PREST_PG_URL env var value, so that you can connect to your Postgres instance.
- postgres://admin:@localhost:5432/my-db (if there is no password)
If your password contains special characters (e.g. #, %, $, @, etc.), you need to URL encode them in the
PREST_PG_URLenv var (e.g. %40 for @). You can check the logs to see if the database credentials are proper and if pREST is able to connect to the database. pREST needs access permissions to your Postgres database as described in permissions page.
If your Postgres instance is running on
localhost, the following changes will be needed to the
docker run command to allow the Docker container to access the host’s network.
--net=host flag to access the host’s Postgres service.
This is what your command should look like:
1docker run -d --net=host -p 3000:3000 \ 2 -e PREST_PG_URL=...
if you are using another operating system we recommend reading the docker network documentation, on macOS and Windows it is different.
With Docker Compose
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. To learn more about all the features of Compose, see the list of features.
Download docker compose file
1wget https://raw.githubusercontent.com/prest/prest/main/docker-compose-prod.yml -O docker-compose.yml
Up (run) PostgreSQL and prestd
Run data migration to create user structure for access (JWT)
1docker-compose exec prest prestd migrate up auth
Create user and password for API access (via JWT)
- user: prest
- pass: prest
1docker-compose exec postgres psql -d prest -U prest -c "INSERT INTO prest_users (name, username, password) VALUES ('pREST Full Name', 'prest', MD5('prest'))"
Check if the user was created successfully (by doing a select on the table)
1docker-compose exec postgres psql -d prest -U prest -c "select * from prest_users"
First call on API
1curl -i -X GET http://127.0.0.1:3000/databases -H "Content-Type: application/json"