从主机映射卷更改时,容器文件未更新

时间:2017-05-21 22:13:15

标签: docker docker-compose docker-for-windows docker-desktop

我有以下docker-compose.yml

version: '3'

services:
  web:
    build: 
      context: .
      dockerfile: ./.docker/node.dockerfile
    volumes:
      - D:\Proj\Web:/app
    ports:
      - '3000:3000'
    depends_on: 
      - 'db'
    networks:
      - holder-network
    restart: on-failure
    tty: true


  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - holder-network
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: P@ssw0rd
      MYSQL_DATABASE: holder_db
      MYSQL_USER: holder_usr
      MYSQL_PASSWORD: P@ssw0rd


networks:
  holder-network:
    driver: bridge

volumes:
  db_data:

node.dockerfile

FROM node:7.10

MAINTAINER Juliano Nunes

RUN mkdir /var/www

RUN npm install nodemon -g

WORKDIR /var/www

ADD . /var/www

RUN npm install

CMD nodemon

我正在从主机更改D:\Proj\Web下的文件,但它不会更新容器中的文件。为什么呢?

2 个答案:

答案 0 :(得分:2)

我发现了错误。我的docker-compose.yml使用/app作为路径,node.dockerfile正在使用/var/www

这是更新的(工作)版本:

version: '3'

services:
  web:
    build: 
      context: .
      dockerfile: ./.docker/node.dockerfile
    volumes:
      - D:\Proj\Web:/var/www
    ports:
      - '3000:3000'
    depends_on: 
      - 'db'
    networks:
      - holder-network
    restart: on-failure
    tty: true


  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - holder-network
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: P@ssw0rd
      MYSQL_DATABASE: holder_db
      MYSQL_USER: holder_usr
      MYSQL_PASSWORD: P@ssw0rd


networks:
  holder-network:
    driver: bridge

volumes:
  db_data:

答案 1 :(得分:0)

要在docker for windows上运行的容器中映射主机卷,您需要确保将驱动器共享到嵌入式VM中。否则,该目录将从VM的文件系统挂载,该文件系统在该位置将为空。您需要进入Windows上的docker设置并将D驱动器添加到共享目录列表中。请在此处查看docker的文档:https://docs.docker.com/docker-for-windows/#shared-drives