Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

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 thiseggheadio video.)

Create adocker-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 modeExit fullscreen mode

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

mkdir pgdatadocker-compose up -d
Enter fullscreen modeExit fullscreen mode

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

docker-compose run db bash
Enter fullscreen modeExit fullscreen mode

Inside the docker container run the following and enter passwordwonderland defined above.

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

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

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

npx prisma initnpx prisma generate
Enter fullscreen modeExit fullscreen mode

Now you can run the following command to create andapply migrations.

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

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More fromMadhav Jha

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp