Skip to content

Instantly share code, notes, and snippets.

@alexturek
Last active January 10, 2016 22:58
Show Gist options
  • Save alexturek/f4752283cb87ced581fc to your computer and use it in GitHub Desktop.
Save alexturek/f4752283cb87ced581fc to your computer and use it in GitHub Desktop.
Run Postgres in docker, but expose it locally like it's native
# Make a VirtualBox VM with enough memory
docker-machine create --driver virtualbox --virtualbox-memory 8096 default
# Map the VirtualBox VM ports 5432 to localhost
VBoxManage controlvm default natpf1 "tcp-port5432,tcp,,5432,,5432"
# If this VM will be reused, bake port mapping into the VM
VBoxManage modifyvm default --natpf1 "tcp-port5432,tcp,,5432,,5432"
# Run a Postgres instance
# docker run -d --name "postgres-in-docker" -e POSTGRES_USER=`whoami` -p 5432:5432 postgres
# If you want postgis installed (I do)
# docker run -d --name "postgres-in-docker" -e POSTGRES_USER=`whoami` -p 5432:5432 mdillon/postgis:9.4
# Does this work?
psql -h localhost -c "select 1;"
@alexturek
Copy link
Author

docker-machine start default - sometimes you can just restart the VM on startup

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