我有一个正在 dockerizing 的开发环境,我希望能够实时重新加载我的更改,而无需重建 docker 映像。我正在使用 docker compose,因为 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
原文由 Amin Shah Gilani 发布,翻译遵循 CC BY-SA 4.0 许可协议
查看他们的 文档
从外观上看,您可以在 docker-compose.yml 上执行以下操作
其中
./
是主机目录,而/app
是容器的目标目录。编辑:
以前的文档源现在指向版本历史记录,您必须选择您正在使用的 compose 版本并查找参考。
懒人 – v3 / v2 / v1
旁注:截至本次编辑,所有版本的语法保持不变