Fix docker-compose, add postgres init script
This commit is contained in:
committed by
=Michael Hohn
parent
9c0cdb1fe4
commit
4b721b5969
@@ -99,7 +99,10 @@ These are simple steps using a single container.
|
|||||||
|
|
||||||
### Manually create needed postgres databases
|
### Manually create needed postgres databases
|
||||||
|
|
||||||
This is still necessary after `docker-compose up` to avoid
|
docker-compose now runs a db init script, but this information is useful for
|
||||||
|
debugging/manual work.
|
||||||
|
|
||||||
|
~~This is still necessary after `docker-compose up` to avoid~~
|
||||||
|
|
||||||
[error] failed to initialize database, got error failed to connect to
|
[error] failed to initialize database, got error failed to connect to
|
||||||
`user=exampleuser database=server_db`: 172.25.0.3:5432 (postgres): server
|
`user=exampleuser database=server_db`: 172.25.0.3:5432 (postgres): server
|
||||||
@@ -122,7 +125,7 @@ The steps:
|
|||||||
# List all dbs
|
# List all dbs
|
||||||
\l
|
\l
|
||||||
|
|
||||||
To run pgmin, the minimal go/postgres test part of this repository:
|
### To run pgmin, the minimal go/postgres test part of this repository
|
||||||
|
|
||||||
1. Run pgmin
|
1. Run pgmin
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ services:
|
|||||||
POSTGRES_PASSWORD: examplepass
|
POSTGRES_PASSWORD: examplepass
|
||||||
POSTGRES_DB: exampledb
|
POSTGRES_DB: exampledb
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/Users/hohn/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
- ./postgres-init-scripts:/docker-entrypoint-initdb.d
|
||||||
ports:
|
ports:
|
||||||
- "5432:5432" # Exposing PostgreSQL to the host
|
- "5432:5432" # Exposing PostgreSQL to the host
|
||||||
expose:
|
expose:
|
||||||
@@ -38,7 +39,7 @@ services:
|
|||||||
container_name: server
|
container_name: server
|
||||||
command: sh -c "apt-get update && apt-get install -y curl && tail -f /dev/null"
|
command: sh -c "apt-get update && apt-get install -y curl && tail -f /dev/null"
|
||||||
ports:
|
ports:
|
||||||
- "8080:80" # Exposing port 80 inside the container as port 8080 on the host
|
- "8080:8080"
|
||||||
volumes:
|
volumes:
|
||||||
- /Users/hohn/work-gh/mrva/mrvacommander:/mrva/mrvacommander
|
- /Users/hohn/work-gh/mrva/mrvacommander:/mrva/mrvacommander
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
8
postgres-init-scripts/dbinit.sh
Executable file
8
postgres-init-scripts/dbinit.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||||
|
SELECT 'CREATE DATABASE server_db' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'server_db')\gexec
|
||||||
|
SELECT 'CREATE DATABASE querypack_db' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'querypack_db')\gexec
|
||||||
|
SELECT 'CREATE DATABASE qldb_db' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'qldb_db')\gexec
|
||||||
|
EOSQL
|
||||||
Reference in New Issue
Block a user