Docker Compose phpmyadmin登录失败

时间:2019-08-21 07:31:13

标签: docker docker-compose

我在docker-compose.yaml中有以下内容

 db:
  image: mysql:5.7.22
  container_name: db
  restart: unless-stopped
  tty: true
  ports:
   - "3306:3306"
  environment:
    MYSQL_DATABASE: pos
    MYSQL_ROOT_PASSWORD: 5378
    SERVICE_TAGS: dev
    SERVICE_NAME: mysql
  volumes:
  - dbdata:/var/lib/mysql
  - ./dockerconfig/mysql/my.cnf:/etc/mysql/my.cnf
  networks:
  - app-network

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: pepo_phpmyadmin
    ports:
    - 8000:80
    environment:
    - PMA_ARBITRARY=1
    - PMA_HOST=pepo_mysql
    depends_on:
    - db
    restart: always

#Docker Networks
networks:
 app-network:
driver: bridge

因此,当我访问localhost:800时,将显示如下所示的phpmyadminlogin页面

enter image description here

我尝试使用以下凭据

server:db
username:root
password:5378

但是它总是失败,并显示错误mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known 我尝试将服务器字段从db更改为phpmyadmin,但遇到错误mysqli_real_connect(): (HY000/2002): Connection refused

我需要使用什么凭证 我错过了什么?

php部分的补充

webserver:
 image: nginx
 container_name: webserver
 restart: unless-stopped
 tty: true
 ports:
 - "80:80"
 - "443:443"
 volumes:
  - ./:/var/www
  - ./dockerconfig/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network

1 个答案:

答案 0 :(得分:2)

您需要将网络添加到您的php中:

 phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: pepo_phpmyadmin
    ports:
     - 8000:80
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOST=db
    depends_on:
      - db
    restart: always
    networks:
      - app-network

然后将db放入服务器字段

并将PMA_HOST=pepo_mysql更改为PMA_HOST=db