Docker node development environment on windows

徘徊边缘 提交于 2019-12-07 21:18:50

问题


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"]

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?

Thanks!


回答1:


At least during development, you could share a folder from your windows OS with docker - would make the code-debug cycle a lot quicker.

Mount a Host Directory as a Data Volume: https://docs.docker.com/userguide/dockervolumes/

(about 1/2 way down the page)




回答2:


Try the following:

FROM node
COPY ./package.json /src
RUN cd /src && npm install
COPY . src/
EXPOSE  3000
CMD ["node", "/src/express.js"]

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.



来源:https://stackoverflow.com/questions/30873748/docker-node-development-environment-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!