This repository contains a Pulumi setup for deploying a PostgreSQL database locally using Docker. Follow the steps below to set up and verify your local PostgreSQL instance.
Before you begin, ensure you have the following installed on your machine:
- Docker: Install Docker
- Pulumi: Install Pulumi
Clone this repository, and
cd pulumi-postgres-local
Initialize the Pulumi project and create a new stack:
pulumi new docker-python
pulumi stack init prod
Install Python dependencies:
pip install -r requirements.txt
Copy .env_example
to .env
and add your own values.
Create a directory on your host machine to store PostgreSQL data files:
sudo mkdir -p /path/to/your/data
sudo chown 1000:1000 /path/to/your/data # Replace 1000:1000 with the appropriate UID:GID if necessary
Deploy the Pulumi stack to start the PostgreSQL container:
pulumi up
Verify that the PostgreSQL container is running:
docker ps
You should see a container name matching what you have in your .env
file. If your project scope goes beyond local
deployment, you might want to consider where to put secrets and where to put other variables.
You can connect to the PostgreSQL instance using psql
or any database management tool like DBeaver or pgAdmin.
psql -h localhost -U your_username -d your_database
- Open DBeaver.
- Click on the New Database Connection button.
- Select PostgreSQL from the list of database types.
- Enter the connection details:
- Host:
localhost
- Port:
5432
- Database:
your_database
- Username:
your_username
- Password:
your_password
- Host:
- Click Finish to establish the connection.
You have successfully set up a local PostgreSQL database using Pulumi and Docker. Feel free to customize the setup as needed for your projects.
- Replace
your_username
,your_password
,your_database
, and/path/to/your/data
with your actual values. - Ensure you have the correct permissions for the data directory on your host machine.
To see the changes Pulumi will apply without actually making them:
pulumi preview
To remove all resources created by Pulumi:
pulumi destroy