问题描述
我正在开发一个简单的NodeJS应用程序.我使用docker,它使部署到生产环境变得非常容易.这是我的Dockerfile:
I'm developing a simple NodeJS application. I use docker and it makes it very easy to deploy to production.This is my Dockerfile:
FROM node
COPY . /src
RUN cd /src; npm install
EXPOSE 3000
CMD ["node", "/src/express.js"]
在我的开发环境(Windows,boot2Docker)上,Docker拖慢了我的速度,因为我所做的每一个小改变,我都必须重新构建Docker映像并运行容器,这需要几分钟.我找不到简单地将源文件从主机复制到docker容器的方法.有一个简单的方法吗?我应该在开发环境上使用纯NodeJS,而仅在生产环境中使用Docker吗?
On my development environment (windows, boot2Docker) Docker is slowing me down, because for every small change I do, I have to re-build the Docker image and run the container and it takes a few minutes.
I couldn't find a way to simply copy my source files from the host to the docker container. Is there an easy way to do it? Should I use plain nodeJS on my development environment and only use Docker in production?
谢谢!
推荐答案
尝试以下操作:
FROM node
COPY ./package.json /src
RUN cd /src && npm install
COPY . src/
EXPOSE 3000
CMD ["node", "/src/express.js"]
您每次在src
中进行更改时,最初使用的方式将安装npm软件包.如果我们分开此步骤,则仅在package.json
文件更改的情况下才安装这些软件包.
The way you originally have it will install npm packages everytime you change something within src
. If we separate this step, these packages will only be installed if the package.json
file changes.
这篇关于Windows上的Docker节点开发环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!