Skip to content

Commit 94e5794

Browse files
committed
Fixed user/pass issue for initialization scripts, added docs
1 parent 7c6b9d8 commit 94e5794

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

docker-entrypoint.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,28 @@ exec_sql() {
9191

9292
echo "running psql command found in: "
9393
echo $(which psql)
94+
95+
local user=$DOLTGRES_USER
96+
local password=$DOLTGRES_PASSWORD
97+
98+
# use the default user and pass if not specified in the env
99+
if [ -z $user ]; then
100+
user="postgres"
101+
fi
102+
103+
if [ -z $password ]; then
104+
password="password"
105+
fi
94106

95107
while true; do
96108
if [ -n "$query" ]; then
97109
set +e
98-
output=$(PGPASSWORD=password psql -h 127.0.0.1 -U postgres -c "$query" 2>&1)
110+
output=$(PGPASSWORD=$password psql -h 127.0.0.1 -U $user -c "$query" 2>&1)
99111
status=$?
100112
set -e
101113
else
102114
set +e # tmp disabled to initdb.d/ file err
103-
output=$(PGPASSWORD=password psql -h 127.0.0.1 -U postgres < /dev/stdin 2>&1)
115+
output=$(PGPASSWORD=$password psql -h 127.0.0.1 -U $user < /dev/stdin 2>&1)
104116
status=$?
105117
set -e
106118
fi
@@ -304,7 +316,6 @@ start_server() {
304316
db=$(get_env_var "DB")
305317
export DOLTGRES_USER=$user
306318
export DOLTGRES_PASSWORD=$password
307-
export DOLTGRES_DB=$db
308319

309320
SERVER_PID=-1
310321

dockerREADME.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ For convenience, `POSTGRES_USER` and `POSTGRES_PASSWORD` are accepted as aliases
102102
To create additional users, connect to the running database and issue `CREATE ROLE` and `GRANT`
103103
statements as the super-user.
104104

105+
## Initialization
106+
107+
By default, the Doltgres server is initialized with a single empty database with the same name as
108+
the system user (`postgres` by default). You can add additional data or execute arbitrary SQL setup
109+
by including initialization scripts in the mounted volume
110+
`/docker-entrypoint-initdb.d/`. Initialization scripts must have the `.sql` file extension and
111+
contain statements separated by semicolons. They can be optionally compressed as `.bz2`, `.gz`,
112+
`.xz`, or `.zst` files with the appropriate extension suffix, e.g. `init.sql.gz`.
113+
114+
Specify an initialization script directory as a volume with `docker run`:
115+
116+
```shell
117+
$ docker run -v ./init_scripts:/docker-entrypoint-initdb.d/ -p 5432:5432 dolthub/doltgresql:latest
118+
```
119+
105120
## Environment Variables
106121

107122
The Doltgres image supports the following environment variables:
@@ -111,5 +126,3 @@ The Doltgres image supports the following environment variables:
111126
an alias.
112127
- `DOLTGRES_DATA`: Specifies a path in the container to store database data, created if it doesn't
113128
exist (default: `/var/lib/doltgresql/`). `PGDATA` is an alias.
114-
- `DOLTGRES_DB`: Specifies a database name to be created (default: none). The `postgres` database is
115-
still created.

0 commit comments

Comments
 (0)