In the mysql docker hub page there's a reference on how to create users with:
MYSQL_USER, MYSQL_PASSWORD
But how can you specify those parameters on the docker-compose.yml file?
So far I have:
mysql:
image: mysql:5.7
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: R00t+
Another question; how can I connect to the mysql host from outside the container? Inside the container I can connect using:
$user = 'root';
$pass = 'R00t+';
$server = 'mysql';
$dbh = new PDO( "mysql:host=$server", $user, $pass );
About password you are setting all parameters exactly the same as you set root password which is:
mysql:
image: mysql:5.7
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: R00t+
MYSQL_USER: youruser
MYSQL_PASSWORD: yourpassword
To connect with mysql outside container just as host use localhost
because you redirect ports from container to host machine in this line - "3306:3306"
$user = 'root';
$pass = 'R00t+';
$server = 'localhost';
$dbh = new PDO( "mysql:host=$server", $user, $pass );
I assume you are running it on your laptop where you have docker containers started.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With