Skip to content
This repository has been archived by the owner on Jul 19, 2020. It is now read-only.

docker psql

Alex edited this page Jun 26, 2018 · 1 revision

Docker + PSQL

Install docker from docker store.

Run docker-daemon and pull postgres (alpine version in current example) image. In docker-toolbox for Windows it can be done like this (in powershell only):

# iex == InvokeExpression
docker-machine start; docker-machine env | iex
docker pull postgres:alpine

Run docker instance:

# setup env variables manually
docker run --rm --name my-psql -p 5432:5432 -e POSTGRES_PASSWORD=pass123 -e POSTGRES_USER=user -e POSTGRES_DB=mydb -t postgres:alpine

Read more in documentation.

Then connection to database from python can be done like this (for peewee):

from playhouse.pool import PostgresqlDatabase

db = PostgresqlDatabase(
    database="mydb",
    host="localhost",
    port=5432,
    user="user",
    password="pass123",
    autorollback=True
)
Clone this wiki locally