I have a school project which involves building 3 containers (NGINX, MariaDB and WordPress) and linking them together with docker-compose.
When I run the make command, an error appears when building the MariaDB container:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
My MariaDB container is built using the following script auto_config.sh
:
#!/bin/sh
service mysql start;
mysql -e "CREATE DATABASE IF NOT EXISTS \`${SQL_DATABASE}\`;"
mysql -e "CREATE USER IF NOT EXISTS \`${SQL_USER}\`@'localhost' IDENTIFIED BY '${SQL_PASSWORD}';"
mysql -e "GRANT ALL PRIVILEGES ON \`${SQL_DATABASE}\`.* TO \`${SQL_USER}\`@'%' IDENTIFIED BY '${SQL_PASSWORD}';"
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '${SQL_ROOT_PASSWORD}';"
mysql -e "FLUSH PRIVILEGES;"
mysqladmin -u root -p$SQL_ROOT_PASSWORD shutdown
exec mysqld_safe
And the environment variables are defined in an .env (I obviously changed the information before putting it here):
DOMAIN_NAME=whatever.42.fr
#sql
SQL_DATABASE=whatever
SQL_USER=whatever_user
SQL_PASSWORD=whatever_password
SQL_ROOT_PASSWORD=whatever_password
#wordpress
SITE_TITLE=whatever
ADMIN_USER=whatever
ADMIN_PASSWORD=whatever_password
ADMIN_EMAIL=whatever@gmail.com
#user
USER1_LOGIN=whatever
USER1_PASS=whatever_password
USER1_MAIL=whatever@gmail.com
To find the errors I decided to type the commands of my auto_config.sh script one by one after doing docker build -t mariadb .
but when I docker run --env-file /home/my_login/srcs/.env -it mariadb
the errors appear again:
[ ok ] Starting MariaDB database server: mysqld.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Then my program crashes.
Do you know how I could solve it? I absolutely have to hand in my work before Friday and I am losing hope lol