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

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay