簡體   English   中英

為什么phpmyadmin和mysql docker容器之間的連接不起作用

[英]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 我究竟做錯了什么? 謝謝。

我使用以下操作:

  1. docker-compose down && docker-compose up -d
  2. 鍵入Web瀏覽器http:// localhost:8080
  3. 我以root用戶身份登錄,密碼test
  4. 獲取上述錯誤

的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM