Docker在Windows 10启动:数据库表和绑定目录正在消失

我正在用Win 10使用Docker。当Docker启动时,它会自动创build带有MySQL的容器,这非常棒。 问题是数据库表和绑定目录正在消失。 为了使它们再次出现,我必须切换到每个项目的目录并手动重新创buildconatiner。 每次我的电脑重新启动时,我都必须这样做,这很麻烦:

$ cd env-projX $ docker-compose down $ docker-compose up -d 

任何想法如何解决?

我的docker-compose.yml

 version: '2' services: mysql: image: mysql:5.7 restart: always ports: - "${HOST_IP}:${MYSQL_PORT}:3306" environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_DATABASE: ${MYSQL_DATABASE} MYSQL_USER: ${MYSQL_USER} MYSQL_PASSWORD: ${MYSQL_PASSWORD} volumes: - "./docker/mysql/dump:/home/dumps" - "./docker/mysql/data:/var/lib/mysql" 

更新:

消失的数据库表的解决方法是,当我不再与主机共享数据库文件,说:

 - "db-data:/var/lib/mysql" 

代替

 - "./docker/mysql/data:/var/lib/mysql" 

所以我的configuration看起来像这样:

 version: '2' services: mysql: image: mysql:5.7 restart: always ports: - "${HOST_IP}:${MYSQL_PORT}:3306" environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_DATABASE: ${MYSQL_DATABASE} MYSQL_USER: ${MYSQL_USER} MYSQL_PASSWORD: ${MYSQL_PASSWORD} volumes: - "./docker/mysql/dump:/home/dumps" - "db-data:/var/lib/mysql" volumes: db-data: