如何在Docker Compose中将主机目录挂载为卷 [英] How do I mount a host directory as a volume in docker compose
问题描述
我有一个正在进行dockerizing的开发环境,并且我希望能够实时重新加载所做的更改而不必重建docker映像。我正在使用docker compose,因为redis是我应用程序的依赖项之一,而且我希望能够链接redis容器
I have a development environment I'm dockerizing and I would like the ability to livereload my changes without having to rebuild docker images. I'm using docker compose because redis is one of my app's dependencies and I like being able to link a redis container
我在<$ c $中定义了两个容器c> docker-compose.yml :
node:
build: ./node
links:
- redis
ports:
- "8080"
env_file:
- node-app.env
redis:
image: redis
ports:
- "6379"
我已经到达我的 node
应用程序的dockerfile中的位置,我在其中添加了一个卷,但是如何将主机的目录挂载到该卷中,以便所有活动对代码的编辑是否反映在容器中?
I've gotten to the point in my node
app's dockerfile where I add a volume, but how do I mount the the host's directory in the volume so that all my live edits to the code are reflected in the container?
这是我当前的Dockerfile:
Here's my current 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
From the looks of it you could do the following on your docker-compose.yml
volumes:
- ./:/app
这篇关于如何在Docker Compose中将主机目录挂载为卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!