Skip to content

Instantly share code, notes, and snippets.

@sandys
Created March 20, 2020 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandys/347c4962e90da978798fba1ec56ddab4 to your computer and use it in GitHub Desktop.
Save sandys/347c4962e90da978798fba1ec56ddab4 to your computer and use it in GitHub Desktop.
running postgresql on your laptop without installing it (using docker) . with connections to python

docker network create pg

docker run -it --rm -P -p 5432:5432 --name pg -e POSTGRES_PASSWORD=password -e POSTGRES_USER=postgres -e POSTGRES_DB=production -v pgdata:/var/lib/postgresql/data --network=pg postgres

pgdata is the name of the docker volume. You can check it using docker volume ls and docker volume inspect pgdata. You can delete the docker volume by docker volume rm pgdata and prune all volumes using docker volume prune docker volumes are created in your central docker directory (usually /var/lib/docker/overlay2 ). You generally dont need to care about this.

You can now access it in many ways:

psql postgresql://postgres:password@localhost:5432/production

docker run -it --rm --network pg postgres psql -h pg -U postgres

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment