I have setup wordpress with mariadb containers without any issues.
Now I am trying to test wordpress with mysql.
Commands used:
$ docker run --name mysql01 -e MYSQL_ROOT_PASSWORD=Password1234 -d mysql
$ docker run --name wordpress01 --link mysql01 -p 8080:80 -e WORDPRESS_DB_HOST=mysql01:3306 -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=Password1234 -e WORDPRESS_DB_NAME=wordpress -e WORDPRESS_TABLE_PREFIX=wp_ -d wordpress
status of containers:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e71299679e73 mysql "docker-entrypoint..." 2 minutes ago Up 2 minutes 3306/tcp, 33060/tcp mysql01
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0a7dd46fb33 wordpress "docker-entrypoint..." 5 minutes ago Exited (1) 4 minutes ago wordpress01
e71299679e73 mysql "docker-entrypoint..." 7 minutes ago Up 7 minutes 3306/tcp, 33060/tcp mysql01
Error Logs:
$ docker logs wordpress01
WordPress not found in /var/www/html - copying now...
Complete! WordPress has been successfully copied to /var/www/html
Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
MySQL Connection Error: (2002) Connection refused
Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
MySQL Connection Error: (2002) Connection refused
Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
MySQL Connection Error: (2002) Connection refused
Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Standard input code on line 22
Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in Standard input code on line 22
MySQL Connection Error: (2054) The server requested authentication method unknown to the client
...
WordPress doesn't work by default with MySQL v8 yet as mentioned here. Also, the example in wordpress docker image readme uses MySQL v5.7. Changing mysql version to 5.7 should do the job.
docker run --name mysql01 -e MYSQL_ROOT_PASSWORD=Password1234 -d mysql:5.7
If you need to use mysql:latest docker image, starting mysql with --default-authentication-plugin=mysql_native_password argument should also work as mentioned here.
docker run --name mysql01 -e MYSQL_ROOT_PASSWORD=Password1234 -d mysql --default-authentication-plugin=mysql_native_password
Related
Issue type:
initialization bug with mysql:8 docker official image.
Versions:
Docker version 20.10.14, build a224086;
Linux Ubuntu 21.10 host machine OS;
Docker mysql:8 and mysql:oracle official image tags, both with same bug.
Steps to reproduce:
run mysql:8 docker official image from docker hub passing the needed args at the CLI env variables. Such as:
sudo docker run --name app-mysql-container -v [some-absolute-path-in-your-host-machine]:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=[some-root-password] -e MYSQL_DATABASE=[some-database-name] -e MYSQL_USER=[some-user-name] -e MYSQL_PASSWORD=[some-user-password] -d mysql:8
use another instance of the terminal to follow the logs live of the container just created:
sudo docker --follow logs app-mysql-container
then use at the other instance of the terminal:
sudo docker exec -it app-mysql-container bash , in order to get inside the container bash shell, and type:
mysql -u root -p
[type password]
ERROR HAPPENS CONTINUOUSLY until server finishes getting up - about 8 minutes !!
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
after the 8 minutes, when the mysqld server finally gets ready for connection, with a ready socket connection at 3306 port, then everything starts working fine... both for access from inside the container (MySQL CLI) as from outside linked containers with applications connecting to the mysql server.
Eventually the MySQL server starts almost instantly, rather than after 8 minutes... something is wrong with this docker image...
Printscreens below:
I have a tow running containers one with symfony app and the other is mysql database server:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
99d17c328612 sbc/gestcom:1.0 "docker-php-entrypoi…" 18 hours ago Up 2 minutes 0.0.0.0:4400->80/tcp musing_moser
97dafcfb4acd mysql "docker-entrypoint.s…" 18 hours ago Up 2 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp suspicious_brattain
I linked mysql container to symfony contianer like so:
docker container run -d -p 4400:80 --link suspicious_brattain:db sbc/gestcom:1.0
suspicious_brattain: is the name of the mysql container
sbc/gestcom:1.0: is the name of the image I built that contains my symfony app (with apache, php and pdo driver needed to work with mysql)
Now when I access the symfony app container to run doctrine:database:create I get this exception:
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002] Connection
refused
This is parameters.yml file:
parameters:
database_host: 127.0.0.1
database_port: 3306
database_name: my_database
database_user: root
database_password: root
Of course I gave root as password for mysql image when running it like so:
docker container run -e MYSQL_ROOT_PASSWORD=root -d mysql
And to be sure that the symfony container is linked to mysql container this what I get when I inspect the symfony container:
...
"Links": [
"/suspicious_brattain:/musing_moser/db"
],
...
As you can see they are connected, however I still unable to create my database using symfony command and I get Connection refused!
You shouldn't be trying to connect on 127.0.0.1, but to db.
When linking containers, a /etc/hosts entry is created in the container to make configuration more convenient.
I want to run joomla in docker but failed to do as joomla container is exited and logs show the some warning as:-The server requested authentication method unknown to the client [caching_sha2_password] in /makedb.php on line 20
Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in /makedb.php on line 20
MySQL Connection Error: (2054) The server requested authentication method unknown to the client
this error occurs to the incompatible version of MySQL with Joomla as we pull latest images. So we should pull the MySQL image of version 5.X and latest Joomla image.
The problem can easily be solved with this.
run this command in docker
docker run --name joomla_db -p 3306:3306 -d -e MYSQL_ROOT_PASSWORD=test mysql:5.7
docker run --name joomlaweb --link joomla_db:mysql -p 8080:80 -d joomla
I'm new to Docker and pulled the mysql from the docker hub using following command
docker pull mysql
Now, started mysql instance using following commands.
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql/mysql-server:latest
Unable to find image 'mysql/mysql-server:latest' locally
latest: Pulling from mysql/mysql-server
e64f6e679e1a: Pull complete
799d60100a25: Pull complete
85ce9d0534d0: Pull complete
d3565df0a804: Pull complete
Digest: sha256:59a5854dca16488305aee60c8dea4d88b68d816aee627de022b19d9bead48d04
Status: Downloaded newer image for mysql/mysql-server:latest
1be4f5dde2fb4e1d99e23ee2de5e3b663c7c2d0fabe7ef459cf87385071a2e0d
Now, I've checked what all services are up and running.
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1be4f5dde2fb mysql/mysql-server:latest "/entrypoint.sh mysql" 3 minutes ago Up 3 minutes (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
e7d9e3713f5c ubuntu "/bin/bash" 6 days ago Up 6 days angry_hodgkin
and now I execute the following commands and unable to connect to mysql -
mysql -h127.0.0.1 -ppassword -uroot
-bash: mysql: command not found
Docker version..
docker --version
Docker version 1.12.3, build 6b644ec
Now, I'm getting below erro - EDIT-1
docker exec -it 1be4f5dde2fb bash
bash-4.2# mysql
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
bash-4.2# sudo mysql
bash: sudo: command not found
https://hub.docker.com/r/mysql/mysql-server/
Get in the docker container using the following command
docker exec -it mysql bash
You can then easily connect to MySQL, by executing the following command
mysql -uroot -p
If you are trying to connect from the host machine, then you will have to install the mysql client.
On mac, the command is as follows
brew install mysql
I spin up a docker container for MySQL server
docker run --detach --name=mysql_db_server --env="MYSQL_ROOT_PASSWORD=password" mysql
Then I run another container for phpmyadmin that is linked to MySQL server as follows
docker run --name myadmin -d --link mysql_db_server:mysql -p 8080:80 phpmyadmin/phpmyadmin
I am able to see phpmyadmin on http://localhost:8080 but I am not able to log into it using either
root --- password or
admin --- password
$docker ps -a
output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85e68b8bab30 phpmyadmin/phpmyadmin "/run.sh phpmyadmin" 3 hours ago Up 3 hours 0.0.0.0:8080->80/tcp myadmin
b4d130cdb230 mysql "docker-entrypoint.s…" 3 hours ago Up 3 hours 3306/tcp mysql_db_server
What am I doing wrong?
Use myadmin instead of mysql
docker run --name myadmin -d --link mysql_db_server:myadmin -p 8080:80 phpmyadmin/phpmyadmin
Log in to MySQL console with your user:
For that run the command -- docker exec -it app_db_1 /bin/bash
and now you can login to MYSQL console with your user:
root#5f1d313df243:/# mysql -uroot -ppassword
and change the Authentication Plugin with the password here:
mysql> ALTER USER root IDENTIFIED WITH mysql_native_password BY 'PASS';
you will get output something like this -- Query OK, 0 rows affected (0.08 sec)
exit
exit
Read more about the Preferred Authentication Plugin on the MySQL 8.0 Reference Manual
https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
It will work perfectly with a docker as well as docker-compose:
now you can log in to phpMyAdmin on http://localhost:8080 with root & PASS.
(Don't use port 8080 because it might get a problem when your system already uses 8080 port other processes.)