docker-compose无法连接到mysql

时间:2018-08-20 21:52:25

标签: docker docker-compose docker-container

经过数小时的尝试,我发现自己在搜索谷歌,但仍然无法连接到MySQL。

这是我的docker-compose.yaml

version: '3.5'

services:

  apache:
    build: .
    container_name: apache-dot
    restart: unless-stopped
    volumes:
      - ./www-data:/var/www
    depends_on:
      - mysql
    ports:
      - 80:80

  mysql:
    image: mysql:5.7
    container_name: mysql-dot
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: xxxxxxxx
      MYSQL_DATABASE: xxxxxxx
    volumes:
      - mysql-data:/var/lib/mysql
      - ./mysql-dump:/docker-entrypoint-initdb.d
    ports:
      - 3306:3306

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin-dot
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: xxxxxxx
    depends_on:
      - mysql
    ports:
      - 8000:80

networks:
    default:

volumes:
  mysql-data:
    driver: local

Docker compose正确构建无错误。

docker日志和docker inspect没有发现任何错误。 docker network inspect也看起来不错。

任何帮助将不胜感激。

谢谢。

已解决

我必须添加到PHPMyAdmin服务PMA_HOST: mysql

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin-dot
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: xxxxxxx
      PMA_HOST: mysql  <====
    depends_on:
      - mysql
    ports:
      - 8000:80

0 个答案:

没有答案