Janis-Rullis-IT / lara8-vue3-api

Working examples of various technologies and practices - Docker, PHP8, JSON API, Vue3 + Typescript, Laravel8
MIT License
0 stars 0 forks source link

Docker - change MYSQL latest version to fixed one #4

Closed janis-rullis closed 3 years ago

janis-rullis commented 4 years ago

See pr1. Otherwise, the init script will fail.

janis-rullis commented 3 years ago

The problem

Pulling ruu-mysql (mariadb:latest)...
ERROR: Head "https://registry-1.docker.io/v2/library/mariadb/manifests/latest": dial tcp: lookup registry-1.docker.io: No address associated with hostname
janis-rullis commented 3 years ago

Try 10.6

janis-rullis commented 3 years ago

The change

image: 'mariadb:10.6.4-focal'
janis-rullis commented 3 years ago

Last step - migration fails

rm -f bootstrap/cache/config.php
composer clear-cache
composer dumpautoload -o
composer install
php artisan config:clear
php artisan cache:clear

php artisan migrate
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = forge and table_name = migrations and table_type = 'BASE TABLE')  

Connect via client

Noticed the port is the 3306:3306

The reason could be that this port is taken.

Change to 3346:3306

And restart.

Connect

Raises a connection error

ruu-mysql       | 2021-08-26 15:58:09 11 [Warning] Aborted connection 11 to db: 'unconnected' user: 'ruu-user' host: '172.60.0.1' (Got an error reading communication packets)

Connect directly via containers DB CLI

docker exec -it ruu-mysql bash
mysql -u ruu-user -p

Yes, can connect.

SHOW DATABASES;
| Database           |
+--------------------+
| information_schema |
| ruu                |
| ruu_testing        |
+--------------------+

Check if the port is open to the container

docker ps

Yes, it is open.

Try a different client

Tried MySQL Workbench, now try DBeaver.

Yes, this solved

The client version was not suitable for the MariaDB v.10. Updated Workbench but it still could not connect.

Check port defined in lara's env

Changed it but still the same.

Try connecting from API's mysql client

apt install mysql-client
mysql -uruu-user -p -h172.60.2.13 -P3346

ERROR 2003 (HY000): Can't connect to MySQL server on '172.60.2.13:3346' (111)

Check DB user's perms

SHOW GRANTS;
GRANT USAGE ON *.* TO `ruu-user`@`%` IDENTIFIED BY PASSWORD '*3604E7FC9548DB75969E986CDE4618975FB14F96'
GRANT ALL PRIVILEGES ON `ruu`.* TO `ruu-user`@`%`
GRANT ALL PRIVILEGES ON `ruu_testing`.* TO `ruu-user`@`%`

Could the password be the problem?

No, the password is fine. Tested by connecting with DBeaver.

SHOW TABLES;

''. So no migration table here.

Try to connect to 3306 and not 3346

mysql -uruu-user -p -h172.60.2.13 -P3346

Enter password: ERROR 2003 (HY000): Can't connect to MySQL server on '172.60.2.13:3346' (111)

mysql -uruu-user -p -h172.60.2.13 -P3306
SHOW DATABASES;

ruu, ruu_testing.

So in the local-docker-network it is not using the outer 3346 port

Connection is tested.

Now test via laravel

php artisan migrate
SHOW TABLES;
ingredient
migrations
product

Now it works. Nothing was changed expect the PC was rebooted.

Possible solution

Reboot the host computer :D.