Skip to content

Commit ea73775

Browse files
ltangvaldyosifkit
authored andcommitted
Template: Store root password in file
Storing the password in a file lets us use defaults-extra-file option so we don't put it on the command line
1 parent a8aa1cf commit ea73775

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

.template.Debian/docker-entrypoint.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,16 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
197197
FLUSH PRIVILEGES ;
198198
EOSQL
199199

200+
# Store the password in a file so we don't use it on the command line
201+
install -d -m0700 /tmp/mysql-files
202+
PASSFILE=$(mktemp /tmp/mysql-files/XXXXXXXXXX)
203+
install /dev/null -m0600 "${PASSFILE}"
200204
if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then
201-
mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
205+
cat >"${PASSFILE}" <<EOF
206+
[client]
207+
password="${MYSQL_ROOT_PASSWORD}"
208+
EOF
209+
mysql+=( --defaults-extra-file="${PASSFILE}" )
202210
fi
203211

204212
file_env 'MYSQL_DATABASE'
@@ -232,6 +240,8 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
232240
_note "Stopping server"
233241
_stop_server $pid
234242
_note "Server stopped"
243+
rm -f "${PASSFILE}"
244+
unset PASSFILE
235245
echo
236246
_note "MySQL init process done. Ready for start up."
237247
echo

0 commit comments

Comments
 (0)