【发布时间】:2016-12-07 02:39:59
【问题描述】:
感谢 Docker for Mac,现在可以在 Docker 容器内运行本地开发服务器。我们只需将本地存储库安装为卷即可运行容器。如果我们在本地进行更改,它会在容器上自动更新(感谢卷),我们不必重新启动服务器。
我们无法弄清楚应该如何构建这些图像以用于生产。以这个简单的 Node 服务为例:
FROM node:6
# Install the dependencies outside of the application's volume directory
ADD package.json .npmrc /node/
RUN npm install --prefix /node
# Set up the correct paths for the new node modules installation
ENV NODE_PATH /node/node_modules:$NODE_PATH
ENV PATH $PATH:/node/node_modules/.bin
# Create an endpoint to mount the service's repository
VOLUME /runtime
WORKDIR /runtime
# Expose the application's port
EXPOSE 10010
# Start the server
CMD scripts/start
为了创建我们的生产容器,我们真的很想ADD 文件而不是挂载卷。这样我们就可以部署映像并简单地运行它。使用 Docker 处理此问题的正确方法是什么?
【问题讨论】:
标签: docker dockerfile