Setup PostgreSQL
Self hosted PayloadCMS and PostgreSQL website on Docker
1 min read
This section is 1 min read, full guide is 23 min read
Published Jun 17 2025, updated Jun 19 2025
10
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
CaddyDockerGitHub ActionsJavascriptNextJSPayloadCMSPortainerTailscaleUbuntuUFW
Now we are going to setup PostgreSQL database that our Payload website will use.
Go to ''Stacks' in Portainer and click '+ Add stack'.
Call it something meaningful like 'postgresdb'.
Paste in the web editor:
version: "3.9"
services:
postgresdb:
image: postgres:latest
deploy:
replicas: 1 # Restrict to a single replica
restart: always
environment:
POSTGRES_USER: myusername
POSTGRES_PASSWORD: mypassword
ports:
- "5432:5432"
networks:
- shared_network
volumes:
- pg_data:/var/lib/postgresql/data
volumes:
pg_data:
networks:
shared_network:
external: true
Copy to Clipboard
Replace the myusername and mypassword with whatever you would like to use.
This is set to publish the default port of 5432, if you want to change that then update to "<whateverportnumber>:5432".
You will be able to connect to this database using your database GUI of choice, such as PGAdmin, by using your Tailscale IP address, port number, user and password. We will be locking down access from the main public IP later in this guide, so its only accessible over your Tailscale network.