Skip to content

Instantly share code, notes, and snippets.

@Rishabh04-021
Forked from ChakshuGautam/psql-setup-docker.sh
Last active December 23, 2019 05:47
Show Gist options
  • Select an option

  • Save Rishabh04-021/b16663eb9931bbb0e46a5cec3a740a4f to your computer and use it in GitHub Desktop.

Select an option

Save Rishabh04-021/b16663eb9931bbb0e46a5cec3a740a4f to your computer and use it in GitHub Desktop.
PSQL Docker setup - Cheatbook

Setup docker engine

-p 127.0.0.1:5432:5432 instead of -p 5432:5432. If you don’t explicitly tell it to run on localhost, it’ll run on0.0.0.0 which means other folks on the same network will be able to reach it. https://hub.docker.com/_/postgres => Gives a lot of info regarding docker secrets which should be the way forward.

docker pull postgres

OR for a specifig version

docker pull postgres:10

reference docker pull [OPTIONS] NAME[:TAG|@DIGEST]

mkdir -p $HOME/docker/volumes/postgres

NOTE -

  1. use --rm flag if the docker of the same name already exists.
  2. mount the /var/lib/docker to an external volume using the same -v flag. documentation
docker run --rm --name pg-docker -e POSTGRES_PASSWORD=[PASSWORD] -d -p 0.0.0.0:5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data  postgres

If you are doing a fresh install using external volume then do the following:

example for external volumes

docker run --name pg-docker -e POSTGRES_PASSWORD=[PASSWORD] -d -p 0.0.0.0:5432:5432 -v /mnt/volume_nyc1_03/postgres:/var/lib/postgresql/data  postgres

Check for running dockers

docker ps

Check for all available dockers

docker ps -a

Enter into docker shell

docker exec -it pg-docker /bin/bash
@Rishabh04-021
Copy link
Author

Creating external mount points for data and archives:

docker run --name pg-docker -e POSTGRES_PASSWORD=aggegate -d -p 0.0.0.0:5432:5432 -v /mnt/volume_external/docker-aggegate/pgdata:/var/lib/postgresql/data -v /mnt/archive/postgres:/var/lib/postgresql/9.6/main/archive  postgres:9.6

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