Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alfredormz/94b03bf19caf02d8b7df756b65843a27 to your computer and use it in GitHub Desktop.
Save alfredormz/94b03bf19caf02d8b7df756b65843a27 to your computer and use it in GitHub Desktop.
Dockerized Postgresql development environment

The data volume container

docker create -v /var/lib/postgresql/data --name postgres10.3-data busybox

Creating the postgresql container

docker run --name local-postgres10.3 -e POSTGRES_PASSWORD=postgres -d --volumes-from postgres10.3-data postgres:10.3

Establishing a connection

docker run -it --link local-postgres10.3:postgres --rm postgres:10.3 sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

Exposing Postgresql to the Host

docker run --name local-postgres10.3 -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d --volumes-from postgres10.3-data postgres:10.3

Removing the container

docker stop local-postgres10.3
docker rm -v local-postgres10.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment