Docker Community Forums

Share and learn in the Docker community.

How to make mysql and php work together and without show the database password

dockerhub

(Bill Wang) #1

start mysql container

$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql

Connect to MySQL and manually create new database

$ docker run -it --link mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'

link the database and start php container

$ docker run -d --link mysql:mysql --name myapp -v "$PWD":/var/www/html -p 80:80 php:5.6-apache

first question:

When access my php website: http://localhost/index.php, I got below error:

Fatal Error: Mysql is not supported in your PHP, recompile and try again.

Here is the configure command shows in phpinfo page, seems mysql module has been included in compile.

Configure Command ‘./configure’ ‘–with-config-file-path=/usr/local/etc/php’ ‘–with-config-file-scan-dir=/usr/local/etc/php/conf.d’ ‘–with-apxs2’ ‘–disable-cgi’ ‘–enable-mysqlnd’ ‘–with-curl’ ‘–with-openssl’ ‘–with-readline’ ‘–with-recode’ ‘–with-zlib’

Are there anything missed in official php image?

second question:

When access http://localhost/info.php, I can see phpinfo page.

But it also shows database password in session “Environment”:

MYSQL_ENV_MYSQL_ROOT_PASSWORD  my-secret-pw

and in session “PHP Variables”

_ENV["MYSQL_ENV_MYSQL_ROOT_PASSWORD"]     my-secret-pw

So how to hide the password in phpinfo()?