Ho alcuni problemi di connessione al contenitore docker mysql che ho avviato con docker-compose. Questo è un post lungo (mi dispiace!).che si connette a un contenitore mysql di docker-comporre nega l'accesso ma la finestra mobile che esegue la stessa immagine non è
Qui è la mia finestra mobile-compose.yml di file:
db:
image: mysql:5.7
ports:
- "3306:3306" # I have tried both ports and expose "3306". Still doesn't work
environment:
- MYSQL_ROOT_PASSWORD="secret"
- MYSQL_USER="django"
- MYSQL_PASSWORD="secret"
- MYSQL_DATABASE="myAppDB"
Poi:
$> docker-compose build
db uses an image, skipping #expected!
$> docker-compose up
<<LOTS OF OUTPUT>>
OK, ora ho un attivo e funzionante contenitore finestra mobile corridore mysql: 5.7. Grande! O è? Durante il test nella mia app django, ricevo errori operativi che dicono che l'utente non è autorizzato a connettere il database. Ok, allora forse è il mio Django?
$> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7216f99ca0f mysql:5.7 "docker-entrypoint.sh" 3 minutes ago Up 3 minutes 0.0.0.0:3306->3306/tcp sharpfin_db_1
$> docker-machine ip dev
192.168.99.100
$> mysql -h 192.168.99.100 -P 3306 -u django -p
Enter password:
ERROR 1045 (28000): Access denied for user 'django'@'192.168.99.1' (using password: YES)
ok quindi forse è qualcosa a che fare con la connessione al contenitore docker-compose? Cosa succede se provo a connettermi dall'interno del contenitore docker?
$> docker exec -it c7216f99ca0f /bin/bash
[email protected]:/#
[email protected]:/# mysql -u django -p
Enter password:
ERROR 1045 (28000): Access denied for user 'django'@'localhost' (using password: YES)
ok, quindi la finestra mobile mysql non mi consente di connettermi, non so perché. Vediamo cosa succede quando provo fare questo senza finestra mobile-composizione:
$> docker run --name run-mysql -e MYSQL_ROOT_PASSWORD="secret" -e MYSQL_USER="django" -e MYSQL_PASSWORD="secret" -e MYSQL_DATABASE="myAppDB" -p "3306:3306" mysql:5.7
<<LOTS OF OUTPUT SAME AS BEFORE>>
Ok, così ora abbiamo un contenitore in esecuzione la stessa immagine di prima con le stesse impostazioni. (Penso che questa asserzione non sia probabilmente vera - la docker-compose sta facendo qualcosa di diverso nella finestra mobile).
$> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
73071b929e82 mysql:5.7 "docker-entrypoint.sh" 3 minutes ago Up 3 minutes 0.0.0.0:3306->3306/tcp run-mysql
C'è il mio contenitore (chiamato run-mysql). Connettiamoci!
$> mysql -h 192.168.99.100 -P 3306 -u django -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.12 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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 |
+--------------------+
| information_schema |
| myAppDB |
+--------------------+
2 rows in set (0.01 sec)
mysql>
OK. Puoi accedere. È strano ... Che ne dici dall'interno del container?
$> docker exec -it 73071b929e82 /bin/bash
[email protected]:/# mysql -u django -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.12 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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 |
+--------------------+
| information_schema |
| myAppDB |
+--------------------+
2 rows in set (0.00 sec)
mysql>
Ok, posso entrare dall'esterno e all'interno del contenitore quando lancio con corsa finestra mobile, ma non con finestra mobile-composizione. Cosa sta succedendo? Ci deve essere qualcosa che sta facendo il docker-compose dietro le quinte che cambia il modo in cui il database viene inizializzato.
Tutto ciò di cui sopra è esattamente lo stesso se provo anche con l'utente root. Quindi non è un problema di permessi con l'utente di django.
Qualche idea su come risolvere questo problema?
Grazie per una domanda così ben strutturata. Esattamente il problema che ho avuto e esattamente la soluzione. –
Ho lo stesso problema ma nessuna delle soluzioni fornite funziona. – Link14