如何在Docker组合中将主机目录挂载为卷
我有一个dockerizing的开发环境,我希望能够重新生成我的更改,而无需重新编译Docker镜像。 我使用docker撰写,因为redis是我的应用程序的依赖之一,我喜欢能够链接一个redis容器
我在docker-compose.yml
中定义了两个容器:
node: build: ./node links: - redis ports: - "8080" env_file: - node-app.env redis: image: redis ports: - "6379"
我已经在node
应用程序的dockerfile中添加了一个卷,但是如何在主机上挂载主机的目录,以便我所有的代码都能在代码中反映出来?
这是我目前的Dockerfile:
# Set the base image to Ubuntu FROM node:boron # File Author / Maintainer MAINTAINER Amin Shah Gilani <amin@gilani.me> # Install nodemon RUN npm install -g nodemon # Add a /app volume VOLUME ["/app"] # TODO: link the current . to /app # Define working directory WORKDIR /app # Run npm install RUN npm install # Expose port EXPOSE 8080 # Run app using nodemon CMD ["nodemon", "/app/app.js"]
我的项目是这样的:
/ - docker-compose.yml - node-app.env - node/ - app.js - Dockerfile.js
检查他们的文档
从它的外观你可以在你的docker-compose.yml上做下面的事情
volumes: - ./:/app
这是两件事:
我在docker-compose.yml
添加了卷:
node: volumes: - ./node:/app
我将npm install && nodemon app.js
件移到了CMD
因为RUN
将东西添加到了联合文件系统中,而且我的卷不是UFS的一部分。
# Set the base image to Ubuntu FROM node:boron # File Author / Maintainer MAINTAINER Amin Shah Gilani <amin@gilani.me> # Install nodemon RUN npm install -g nodemon # Add a /app volume VOLUME ["/app"] # Define working directory WORKDIR /app # Expose port EXPOSE 8080 # Run npm install CMD npm install && nodemon app.js