Open mawoka-myblock opened 3 years ago
When you use the docker-compose file, no. Everything necessary gets created and deployed instantly. If, on the other hand you use the container without the compose file, you need to specify the MySQL data in the .env file. If the database is on the same server as the container, you need to use 172.17.0.1 as mysql host ip
I only cloned it and ran sudo dcoker-compose up
. Then it says that it can't connect to the database (friendup-app | mysqladmin: [Warning] Using a password on the command line interface can be insecure. friendup-app | mysqladmin: connect to server at 'friendup-db' failed friendup-app | error: 'Access denied for user 'friendup'@'172.19.0.3' (using password: YES)' friendup-db | 2020-12-30 9:49:02 9 [Warning] Access denied for user 'friendup'@'172.19.0.3' (using password: YES)
)
Edit: A MySQL-Server comes with the container, right?
The friendup-app container is trying to access the database at IP address 172.19.0.3. However the friendup-db container is located at 172.19.0.2
This can be verified from the shell on the friendup-app as follows:
$ docker exec -it friendup-app /bin/bash friendup@f46d85d9e3c4:/opt/friendup$ mysql -u root -p -h 172.19.0.2 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 28 Server version: 5.5.5-10.4.17-MariaDB-1:10.4.17+maria~focal mariadb.org binary distribution
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases; +--------------------+ | Database | +--------------------+ | friendup | | information_schema | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec)
mysql> quit Bye
The friendup-app container is trying to access the database at IP address 172.19.0.3. However the friendup-db container is located at 172.19.0.2
The IP address behind the username@
does not mean the destination where we are connecting to, it means the source IP of the system connecting to MySQL. So lets say for example I have a mysql running at 10.0.0.1
and my computer is at 10.0.0.2
I would connect to MySQL as username@10.0.0.2
. To guarantee that we always have the correct destination IP of a container we are using the Internal naming service of Docker, that way when we do mysql -hfriendup-db -ufriendup -p
we are always reaching the MySQL server behind it, no matter if its IP changed for whatever reason.
I only cloned it and ran
sudo dcoker-compose up
. Then it says that it can't connect to the database (friendup-app | mysqladmin: [Warning] Using a password on the command line interface can be insecure. friendup-app | mysqladmin: connect to server at 'friendup-db' failed friendup-app | error: 'Access denied for user 'friendup'@'172.19.0.3' (using password: YES)' friendup-db | 2020-12-30 9:49:02 9 [Warning] Access denied for user 'friendup'@'172.19.0.3' (using password: YES)
)Edit: A MySQL-Server comes with the container, right?
Yes, MySQL comes with the container and that error message you are recieving is implying a wrong username or password or that the MySQL server is still starting up, because I am using mysqladmin to determine if the MySQL server finished starting up, that way we can run all necessary preparations without the risk of them not completing successfully. So if you followed the docker-compose instructions and have been using docker-compose up
you just need to wait a little while while the MySQL server is starting up, during that time it will display access denied errors, which I sadly cannot fix since it directly prints to stderr.
I am stupid but I will ask anyway: Do I need a Database or does the container create one?