Restoring mattermost DB from docker file

Summary

I am trying to do a db restore from docker by declaring

  • ./db/postgres.sql:/docker-entrypoint-initdb.d/initdb.sql

Inside docker-compose.yml


Observed behavior

However I am getting this error message from the docker db logs

/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/initdb.sql
SET
SET
SET
ERROR: cannot drop the currently open database
STATEMENT: DROP DATABASE mattermost;
psql:/docker-entrypoint-initdb.d/initdb.sql:14: ERROR: cannot drop the currently open database


I have tried multiple ways to declare the initdb but keeps having the same problem. I know I can restore it by doing docker exec -i mattermost_db_1 psql -U mmuser mattermost < db/postgres.sql but I want to avoid that method if possible

Iā€™m not sure but maybe it is because the initdb.sql script is run as the postgres user. When you use docker exec you run the command as root user.

1 Like