为什么phpmyadmin和mysql docker容器之间的连接不起作用

时间:2019-08-10 13:58:48

标签: mysql linux docker phpmyadmin

我正在尝试将phpmyadmin容器连接到mysql容器以查看数据库。 phpmyadmin Web界面返回错误super()Cannot log in to the MySQL server。 我究竟做错了什么?谢谢。

我使用以下操作:

  1. mysqli_real_connect(): (HY000/2002): No route to host
  2. 键入Web浏览器http://localhost:8080
  3. 我以用户docker-compose down && docker-compose up -d的身份登录,密码为root的用户
  4. 获取上述错误

我的 docker-compose.yml

test

1 个答案:

答案 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帮助下彼此看到。