Had the same problem inside the script at the entry point. Below is a snippet of my Dockerfile
# init execution ENTRYPOINT ["/usr/local/sbin/initpostgres.sh"]
with the following commands inside an intipostgres.sh script
su postgres -c "pg_ctl start -l /var/lib/postgresql/logpostgres" su postgres -c "createuser -s $OPENERPUSER"
adding sleep 1 before the createuser command on @seanmcl suggested a fix for me:
su postgres -c "pg_ctl start -l /var/lib/postgresql/logpostgres" sleep 1 su postgres -c "createuser -s $OPENERPUSER"
source share