Fixed user/pass issue for initialization scripts, added docs

This commit is contained in:
Zach Musgrave
2026-04-15 10:20:33 -07:00
parent 7c6b9d817d
commit 94e5794adb
2 changed files with 29 additions and 5 deletions
+14 -3
View File
@@ -91,16 +91,28 @@ exec_sql() {
echo "running psql command found in: "
echo $(which psql)
local user=$DOLTGRES_USER
local password=$DOLTGRES_PASSWORD
# use the default user and pass if not specified in the env
if [ -z $user ]; then
user="postgres"
fi
if [ -z $password ]; then
password="password"
fi
while true; do
if [ -n "$query" ]; then
set +e
output=$(PGPASSWORD=password psql -h 127.0.0.1 -U postgres -c "$query" 2>&1)
output=$(PGPASSWORD=$password psql -h 127.0.0.1 -U $user -c "$query" 2>&1)
status=$?
set -e
else
set +e # tmp disabled to initdb.d/ file err
output=$(PGPASSWORD=password psql -h 127.0.0.1 -U postgres < /dev/stdin 2>&1)
output=$(PGPASSWORD=$password psql -h 127.0.0.1 -U $user < /dev/stdin 2>&1)
status=$?
set -e
fi
@@ -304,7 +316,6 @@ start_server() {
db=$(get_env_var "DB")
export DOLTGRES_USER=$user
export DOLTGRES_PASSWORD=$password
export DOLTGRES_DB=$db
SERVER_PID=-1
+15 -2
View File
@@ -102,6 +102,21 @@ For convenience, `POSTGRES_USER` and `POSTGRES_PASSWORD` are accepted as aliases
To create additional users, connect to the running database and issue `CREATE ROLE` and `GRANT`
statements as the super-user.
## Initialization
By default, the Doltgres server is initialized with a single empty database with the same name as
the system user (`postgres` by default). You can add additional data or execute arbitrary SQL setup
by including initialization scripts in the mounted volume
`/docker-entrypoint-initdb.d/`. Initialization scripts must have the `.sql` file extension and
contain statements separated by semicolons. They can be optionally compressed as `.bz2`, `.gz`,
`.xz`, or `.zst` files with the appropriate extension suffix, e.g. `init.sql.gz`.
Specify an initialization script directory as a volume with `docker run`:
```shell
$ docker run -v ./init_scripts:/docker-entrypoint-initdb.d/ -p 5432:5432 dolthub/doltgresql:latest
```
## Environment Variables
The Doltgres image supports the following environment variables:
@@ -111,5 +126,3 @@ The Doltgres image supports the following environment variables:
an alias.
- `DOLTGRES_DATA`: Specifies a path in the container to store database data, created if it doesn't
exist (default: `/var/lib/doltgresql/`). `PGDATA` is an alias.
- `DOLTGRES_DB`: Specifies a database name to be created (default: none). The `postgres` database is
still created.