Created
January 26, 2021 05:20
-
-
Save narate/f1077566f7f267b5b1911bcbe530cea6 to your computer and use it in GitHub Desktop.
Create PostgreSQL user/password wirh database in PostgreSQL running in docker container
This file contains 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
#!/bin/sh | |
# https://github.com/docker-library/postgres/issues/151 | |
set -x | |
POSTGRES="psql --username ${POSTGRES_USER}" | |
echo "Before" | |
echo "======" | |
$POSTGRES <<-SQL | |
\du | |
SQL | |
echo -n "[*] Creating database role: ${DB_USER}... " | |
$POSTGRES <<-SQL | |
CREATE USER ${DB_USER} WITH CREATEDB PASSWORD '${DB_PASSWORD}'; | |
SQL | |
echo -n "[*] Creating database ${DB_NAME}... " | |
$POSTGRES <<-SQL | |
CREATE DATABASE ${DB_NAME} OWNER ${DB_USER}; | |
SQL | |
echo | |
echo "After" | |
echo "=====" | |
$POSTGRES <<-SQL | |
\du | |
SQL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
with
docker
commandwith
docker-compose
command