![](/img/trans.png)
[英]MySQL server in a docker container doesn't work after commiting the container
[英]Why connection between phpmyadmin and mysql docker container doesn't work
我正在嘗試將phpmyadmin容器連接到mysql容器以查看數據庫。 phpmyadmin Web界面返回錯誤Cannot log in to the MySQL server
使用mysqli_real_connect(): (HY000/2002): No route to host
Cannot log in to the MySQL server
mysqli_real_connect(): (HY000/2002): No route to host
。 我究竟做錯了什么? 謝謝。
我使用以下操作:
docker-compose down && docker-compose up -d
root
用戶身份登錄,密碼test
我的docker-compose.yml
version: '2'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: test
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db
ports:
- "8080:80"
參見官方指南 :
您需要指定一些環境才能鏈接到外部mysql容器:
環境變量摘要
PMA_ARBITRARY - when set to 1 connection to the arbitrary server will be allowed
PMA_HOST - define address/host name of the MySQL server
PMA_VERBOSE - define verbose name of the MySQL server
PMA_PORT - define port of the MySQL server
PMA_HOSTS - define comma separated list of address/host names of the MySQL servers
PMA_VERBOSES - define comma separated list of verbose names of the MySQL servers
PMA_PORTS - define comma separated list of ports of the MySQL servers
PMA_USER and PMA_PASSWORD - define username to use for config authentication method
PMA_ABSOLUTE_URI - define user-facing URI
對於您來說,mysql名稱是db
,因此您需要執行下一步:
version: '2'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: test
ports:
- "3306:3306"
command: --default-authentication-plugin=mysql_native_password
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "8080:80"
environment:
PMA_HOSTS: db
另外,-- --link
取消,只需將其刪除, --link
docker-compose
會自動為您設置網絡,以使容器在dns幫助下彼此看到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.