Page MenuHomeDevCentral

MySQL instance should generate a random password if MYSQL_ROOT_PASSWORD isn't set
Closed, WontfixPublic

Description

Currently, our acquisitariat container is launched by the following script:

#!/bin/sh

INSTANCE_NAME=acquisitariat
MYSQL_ROOT_PASSWORD=`openssl rand -hex 21`
MYSQL_DATADIR=/data/$INSTANCE_NAME/mysql

mkdir -p $MYSQL_DATADIR
chcon -Rt svirt_sandbox_file_t $MYSQL_DATADIR
docker run -d \
  -e MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD \
  -v $MYSQL_DATADIR:/var/lib/mysql \
  --name $INSTANCE_NAME nasqueron/mysql

Actually, we don't need to set or know the MYSQL_ROOT_PASSWORD value, as linked containers will recover the value in environment: any container with --link acquisitariat:mysql can access the root password with MYSQL_ENV_MYSQL_ROOT_PASSWORD.

This is what we done in Phabricator container for example:

It would be nice if the image could generate the password.

WARNING: openssl isn't installed on Docker MySQL official image.

Event Timeline

dereckson raised the priority of this task from to Wishlist.
dereckson updated the task description. (Show Details)
dereckson added subscribers: dereckson, Sandlayth.

Generate the password inside the container

An IRC brainstorming gives two solutions to generate the password without installing OpenSSL.

  • < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32
  • to use passwordmaker-cli with rather lite deps: libmhash2 libpcre3 libpcrecpp0

Thanks to teclo- and @Kaliiixx.

Run once a command
D39 shows how to run once a command at container startup.

We can tag this issue good-first-issue, as it has been explored and offer a good opportunity to discover our Docker codebase.

There is an issue: Docker passes the environment to the starting process, but also to linked containers (they need MYSQL_ENV_MYSQL_ROOT_PASSWORD to setup their MySQL database).

According to http://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/#environment-variables sources are ENV instrutions in Dockerfile, and -e options' arguments.

dereckson claimed this task.