Skip to content

Instantly share code, notes, and snippets.

@tricker
Created November 22, 2016 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tricker/cec5f988514fb14b9fb1ea522bd80e35 to your computer and use it in GitHub Desktop.
Save tricker/cec5f988514fb14b9fb1ea522bd80e35 to your computer and use it in GitHub Desktop.
postgres on docker
# postgres / docker
# first install docker on your mac, and start it. you should see the whale widget in task bar
# pull the docker postgres image (for more info see, https://hub.docker.com/_/postgres/ )
docker pull postgres
# run your new sql container
docker run --name tricker-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
# see the active docker containers
docker ps
# copy your sql file from your computer (host) into the docker container (make sure you’re in same dir as the sql file)
docker cp create.sql tricker-postgres:/create.sql
# connect to container command line, note the ugly docker instance id from docker ps above, and insert below instead of 1d62, you don’t have to use the entire 100+ char string, just the first few letters
docker exec -i -t 1d62 /bin/bash
# create your database, named trix in this case
createdb -h localhost -U postgres trix
# confirm you created it, first connect to postgres
psql -U postgres
# then show databases, you should see your new db listed (among others)
\l
#connect to database
\c trix
# quit
\q
# run your create command
psql -U postgres -d trix -f create.sql
#show the tables (you should see the one you just created)
\dt
# show columns in the table we just created
\d+ city
# quit postgres client
\q
# exit the contain
exit
# remove the docker image
docker rm tricker-postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment