-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 -
- use --rm flag if the docker of the same name already exists.
- 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
docker ps
docker ps -a
docker exec -it pg-docker /bin/bash
Creating external mount points for data and archives: