I'm feeling a bit stupid, but...
All I want is a dockerfile that allows me to configure the db and the user to replace a script like
docker run --name $CONTAINER_NAME \
-p 5432:5432 \
-e POSTGRES_PASSWORD=mypass \
-e POSTGRES_DB=mydb \
-d postgres:13.5-alpine
###
### artificial wait here
###
docker exec $CONTAINER_NAME bash -c "psql --username postgres --command \"CREATE USER foo WITH SUPERUSER ENCRYPTED PASSWORD 'bar';\""
I.e. something like this (I thought):
FROM postgres:13.5-alpine
EXPOSE 5432
ENV POSTGRES_DB mydb
ENV POSTGRES_PASSWORD mypass
CMD psql --username postgres --command "CREATE USER foo WITH SUPERUSER ENCRYPTED PASSWORD 'bar';"
except this results in
psql: error: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
So what's the proper way to do this?