Created
April 6, 2017 15:19
-
-
Save kennyballou/4e3fdf67508e74b27480763e105e883c to your computer and use it in GitHub Desktop.
Local Postgres Container Management
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
| #!/usr/bin/env bash | |
| # postgres.sh -- docker postgres helper script | |
| # Copyright (C) 2017 Kenny Ballou | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation, either version 3 of the License, or | |
| # (at your option) any later version. | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # You should have received a copy of the GNU General Public License | |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| IMAGE=postgres:latest | |
| NAME=postgres | |
| function is_running() { | |
| CONTAINER=$(docker ps -a -q --filter name=${NAME}) | |
| } | |
| function start() { | |
| docker run -d \ | |
| -p 5432:5432 \ | |
| --name ${NAME} \ | |
| ${IMAGE} | |
| } | |
| function stop() { | |
| docker stop ${NAME} | |
| docker rm ${NAME} | |
| } | |
| function restart() { | |
| is_running | |
| if [ -n "${CONTAINER}" ]; then | |
| stop | |
| fi | |
| start | |
| } | |
| function status() { | |
| is_running | |
| if [ -n "${CONTAINER}" ]; then | |
| echo $(docker stats --no-stream ${RUNNING} | tail -1) | |
| else | |
| echo "Container is not running" | |
| fi | |
| } | |
| case $1 in | |
| start) | |
| start | |
| ;; | |
| stop) | |
| stop | |
| ;; | |
| status) | |
| status | |
| ;; | |
| restart) | |
| restart | |
| ;; | |
| *) | |
| echo "Not a recognized command" | |
| exit 1 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment