如何在我的docker配置中包括卷?

时间:2019-04-13 13:32:44

标签: docker docker-compose dockerfile

我有一个MEAN应用正常运行的docker-compose配置。

当我按下ctrl + s时,我希望我的角度(ng服务)和快速服务器(nodemon)自动重新运行,就好像我在本地运行我的应用程序一样。

为此,我的容器需要知道文件已更改。

我该怎么做?

Angular的Dockerfile:

FROM node:10

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . ./

EXPOSE 4200

CMD ["npm", "start"]

Express的Dockerfile:

FROM node:6

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . ./

EXPOSE 3000

CMD ["npm", "start"]

docker-compose.yml:

version: '3'

services:
  angular: # name of the first service
    build: client # specify the directory of the Dockerfile
    ports:
      - "4200:4200"

  express: #name of the second service
    build: server # specify the directory of the Dockerfile
    ports:
      - "3000:3000"
    links:
      - database

  database: # name of the third service
    image: mongo
    ports:
      - "27017:27017"

Angular和Express都有一个用于node_modules的.dockerignore

1 个答案:

答案 0 :(得分:0)

如果您处于开发环境中,则可以在volumes中添加docker-compose.yml部分,如下所示:

services:
  angular: # name of the first service
    build: client # specify the directory of the Dockerfile
    ports:
      - "4200:4200"
   volumes:
      - /path/in/host/machine:/path/in/container

  express: #name of the second service
    build: server # specify the directory of the Dockerfile
    ports:
      - "3000:3000"
    links:
      - database
    volumes:
      - /path/in/host/machine:/path/in/container

  database: # name of the third service
    image: mongo
    ports:
      - "27017:27017"

参考:

volumes in docker-compose