Where to take the password from
From the environment inside the container — sh -c '… -p"$MARIADB_ROOT_PASSWORD"' — or from a file:
--password-file, --defaults-extra-file. A database dump without the password on the command line:
docker exec db sh -c 'exec mariadb-dump -u root -p"$MARIADB_ROOT_PASSWORD" --single-transaction app' | gzip > app.sql.gz
The outer single quotes make the shell inside the container expand $MARIADB_ROOT_PASSWORD, not the one on
the host.
If the password has already landed in history or a chat, change it (Secrets in Docker stacks).