Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create postgres docker image for use with postgresguide.com #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions _setup/001-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ date:
categories: setup
permalink: /setup/install.html
---
For Docker
----------
```
# clone repo and cd to docker assets directory
git clone https://github.com/craigkerstiens/postgresguide.com.git
cd postgresguide.com/assets/docker

# run postgres setup script
./setup_postgres.sh

# login to postgres terminal (as "postgres" user, see Dockerfile)
docker exec -it some-postgres psql --dbname pgguide

# confirm that tables have been loaded
pgguide=# \d
```

For Mac
-------
Expand Down
10 changes: 10 additions & 0 deletions assets/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM postgres

MAINTAINER Mike Situ (github.com/shola)

USER postgres
ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD changeme

ADD example.dump /tmp/example.dump
ADD load_sample_data.sh /docker-entrypoint-initdb.d/
4 changes: 4 additions & 0 deletions assets/docker/load_sample_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#~/bin/bash

createdb pgguide
pg_restore --no-owner --dbname pgguide /tmp/example.dump
18 changes: 18 additions & 0 deletions assets/docker/setup_postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# convenience functions for removing all running/exited containers
# add these to your ~/.bash_profile if desired:
# alias rmrfDockerContainers="docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)"
# alias rmrfDockerImages="docker rmi $(docker images)"

# curl example data
curl -L -O http://cl.ly/173L141n3402/download/example.dump

# build postgres image
docker build . -t mypostgres:latest

# run postgres in the background
docker run --name some-postgres mypostgres -d postgres

# login to postgres terminal (as "postgres" user)
docker exec -it some-postgres psql --dbname pgguide