Last active
January 12, 2016 21:10
-
-
Save denibertovic/6130681 to your computer and use it in GitHub Desktop.
Easily start a local Postgres instance for your development environment using docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DATA_DIR="__data" | |
POSTGRES_VERSION=9.3 | |
PORT=5432 | |
.PHONY: docker-check postgres | |
docker-check: | |
@command -v docker >/dev/null 2>&1 || \ | |
{ echo >&2 "Docker needs to be installed and on your PATH. Aborting."; exit 1; } | |
postgres: docker-check | |
@if nmap -PS localhost | grep -q $(PORT); then \ | |
echo "ERROR: Port $(PORT) is already in use..."; \ | |
echo "Maybe Postgres is already running?!"; \ | |
exit 1; \ | |
fi | |
@if [ ! -d $(DATA_DIR)/postgresql ]; then \ | |
echo 'Preparing Postgres persistent data storage...'; \ | |
mkdir -p $(DATA_DIR); \ | |
docker run -v $$PWD/$(DATA_DIR):/tmp/$(DATA_DIR) -i -t \ | |
denibertovic/postgres:$(POSTGRES_VERSION)\ | |
/bin/bash -c "cp -rp var/lib/postgresql /tmp/$(DATA_DIR)"; \ | |
fi | |
@echo "Persistent data storage found."; | |
@echo "Starting postgres..."; | |
@docker run -v $$PWD/$(DATA_DIR)/postgresql:/var/lib/postgresql -d -p $(PORT):$(PORT) \ | |
denibertovic/postgres:$(POSTGRES_VERSION); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment