使用docker时无法访问phpmyadmin

时间:2018-07-25 15:14:22

标签: docker docker-compose

我在项目上使用docker,并按如下方式设置docker-compose文件:

    db_service:
    container_name: database
    image: mysql:latest
    ports:
      - "3306:3306"
    environment:
      - MYSQL_USER=root
      - MYSQL_PASSWORD=mypassword
      - MYSQL_ROOT_PASSWORD=mypassword
      - MYSQL_DATABASE=my_database

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    ports:
      - "8082:80"

当我在http://localhost:8082上登录phpmyadmin时,它显示错误

  

mysqli_real_connect():php_network_getaddresses:getaddrinfo失败:
  名称无法解析

enter image description here

有人知道如何解决此问题吗?

2 个答案:

答案 0 :(得分:1)

尝试链接,依赖和环境变量PMA_HOST

  

db_service:

 container_name: database
 image: mysql:latest
 ports:
   - "3306:3306"
 environment:
   - MYSQL_USER=root
   - MYSQL_PASSWORD=mypassword
   - MYSQL_ROOT_PASSWORD=mypassword
   - MYSQL_DATABASE=my_database
 phpmyadmin:

 image: phpmyadmin/phpmyadmin
 container_name: phpmyadmin 
   depends_on:
   - database
 links:
   - database
 ports:
   - "8082:80"  
     

环境:

   - MYSQL_USER=root
   - MYSQL_ROOT_PASSWORD=mypassword
   - MYSQL_PASSWORD=mypassword
   - PMA_HOST=database

答案 1 :(得分:0)

您需要链接两个容器并提供PHPMyAdmin的登录凭据,以便它可以连接到MySQL实例。请尝试以下操作:

version: '3.2'
    services:
    db_service:
        container_name: database
        image: mysql:latest
        ports:
          - "3306:3306"
        environment:
          - MYSQL_USER=root
          - MYSQL_PASSWORD=mypassword
          - MYSQL_ROOT_PASSWORD=mypassword
          - MYSQL_DATABASE=my_database

    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        links:
          - db_service:mysql
        ports:
          - 8082:80
        environment:
          MYSQL_ROOT_PASSWORD: mypassword