#2002 getaddrinfo失败 - phpmyadmin使用docker容器

时间:2017-11-14 00:32:18

标签: php mysql phpmyadmin docker-compose

我试图通过docker containers连接phpmyadmin和mysql数据库

我有以下docker-compose.yml文件

version: "3"
services:
database:
image: mysql:latest
container_name: locations-service-mysql
environment:
  MYSQL_ROOT_PASSWORD: root
  MYSQL_ALLOW_EMPTY_PASSWORD: "yes"

volumes:
  - ./mysql-init:/var/lib/mysql:rw
  - ./mysql-init/locations_schema.sql:/docker-entrypoint-
    initdb.d/locations_schema.sql:ro


 phpmyadmin:
   image: phpmyadmin/phpmyadmin:latest
   ports:
  - 8181:80
environment:
  MYSQL_USERNAME: root
  MYSQL_ROOT_PASSWORD: examplepass
  PMA_HOST: database


dropwizard:
build: ../locations-service/
ports:
      - 8080:8080
      - 8081:8081
      - 5005:5005
depends_on:
      - database
container_name: locations-service

我尝试使用root帐户和给定密码登录PMA:blabla。 我收到以下错误:

2002 - php_network_getaddresses:getaddrinfo failed:名称无法解析 - 服务器没有响应(或者未正确配置本地服务器的套接字)。

1 个答案:

答案 0 :(得分:2)

似乎"数据库"不在phpmyadmin的容器/ etc / hosts中(它没有链接)

尝试链接

version: "3"
  services:
  database:
    image: mysql:latest
    container_name: locations-service-mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
  volumes:
    - ./mysql-init:/var/lib/mysql:rw
    - ./mysql-init/locations_schema.sql:/docker-entrypoint-initdb.d/locations_schema.sql:ro


 phpmyadmin:
   image: phpmyadmin/phpmyadmin:latest
   links:
     - database
   ports:
    - 8181:80
  environment:
    MYSQL_USERNAME: root
    MYSQL_ROOT_PASSWORD: examplepass
    PMA_HOST: database