Skip to content

Instantly share code, notes, and snippets.

@tricker
Created November 22, 2016 01:21
Show Gist options
  • Select an option

  • Save tricker/cec5f988514fb14b9fb1ea522bd80e35 to your computer and use it in GitHub Desktop.

Select an option

Save tricker/cec5f988514fb14b9fb1ea522bd80e35 to your computer and use it in GitHub Desktop.

Revisions

  1. tricker created this gist Nov 22, 2016.
    47 changes: 47 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    # 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