Postgres
There are multiple ways we can run a postgres database on webapp.io. In this section we’ll cover running postgres with a Dockerfile.
The code for this project is listed in the repository below:
GitHub Repository
Postgres in webapp.io (with Docker)
Postgres & Docker Tutorial
This project will consist of three files in our repository:
- init.sql (what we will initialize our database with)
- Dockerfile (the dockerfile for the postgres database)
- Layerfile (the Layerfile for webapp.io)
Initialize the Database
We’re going to be using the root
user for this postgres database. To do so, we’ll create a script to initialize a database called root
.
Create the Dockerfile
After creating the script to initialize the root database in postgres, we’ll use the postgres:14-bullseye
image from Docker. We’ll set the POSTGRES_USER
as root
, the POSTGRES_PASSWORD
as postgres
, and POSTGRES_DB
as root
.
Create the Layerfile
Once we’ve created the Dockerfile, we can create the Layerfile which will install Docker, build the Docker image, and run the docker image.
The last step is to push this code to your repository. If you’ve connected your repository to webapp.io, webapp.io will get notified of the new commit and run the instructions in the Layerfile.
Entering the Database
To enter the database, click the button “Connect to a debugging terminal” on the Layerfile Runner page, and type in the command psql -h localhost -p 5432
to enter the postgres shell.
If you’re prompted to enter a password, enter in postgres
.