DEV Community

Madhav Jha
Madhav Jha

Posted on

Dockerized postgres for local development

This post describes a quick setup which allows one to develop a postgres sql backed application locally. (This is taken from this eggheadio video.)

Create a docker-compose.yml file as follows.

version: "3.8"
services:
  db:
    image: "postgres:12"
    ports:
      - "54320:5432"
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=alice
      - POSTGRES_PASSWORD=wonderland
      - POSTGRES_DB=myawesomedb

Enter fullscreen mode Exit fullscreen mode

Create a local folder which will persist data and start the service.

mkdir pgdata
docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Once it is up and running, verify you can log into postgres shell.

docker-compose run db bash
Enter fullscreen mode Exit fullscreen mode

Inside the docker container run the following and enter password wonderland defined above.

psql --host=db --username=alice --dbname=myawesomedb
Enter fullscreen mode Exit fullscreen mode

You should see psql shell. You can exit by pressing Ctrl+D twice.

At this point most likely you already have prisma setup locally by some variation of the following commands.

npx prisma init
npx prisma generate
Enter fullscreen mode Exit fullscreen mode

Now you can run the following command to create and apply migrations.

npx prisma migrate dev --name init
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more