我正在尝试将phpmyadmin容器连接到mysql容器以查看数据库。 phpmyadmin Web界面返回错误super()
和Cannot log in to the MySQL server
。
我究竟做错了什么?谢谢。
我使用以下操作:
mysqli_real_connect(): (HY000/2002): No route to host
docker-compose down && docker-compose up -d
的身份登录,密码为root
的用户我的 docker-compose.yml
test
答案 0 :(得分:0)
请参见official guide:
您需要指定一些环境才能链接到外部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
被删除,只需将其删除,docker-compose
会自动为您设置网络,以使容器在dns帮助下彼此看到。