如果有卷,为什么无法连接到数据库?

时间:2019-08-14 18:01:27

标签: docker docker-compose

我有下一个docker-compose.yml

version: '3'
services:
  webserver:
    build: './Docker/apache-php/'
    depends_on:
      - db
    ports:
      - "80:80"
    volumes:
      - ./:/var/www/html/
  db:
    image: mariadb:latest
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: dmm
      MYSQL_USER: dmm
      MYSQL_PASSWORD: password

那很好。我可以使用db:3306地址从Web服务器连接到数据库。

但是,如果我向db容器中添加任何卷

version: '3'
services:
  webserver:
    build: './Docker/apache-php/'
    depends_on:
      - db
    ports:
      - "80:80"
    volumes:
      - ./:/var/www/html/
  db:
    image: mariadb:latest
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: dmm
      MYSQL_USER: dmm
      MYSQL_PASSWORD: password
    volumes:
      - ./db/:/var/lib/mysql/

db:3306拒绝所有连接

怎么了?

0 个答案:

没有答案