DEV Community

Discussion on: Using Docker for Node.js in Development and Production

Collapse
 
orpheus profile image
ohryan

Hey Alex, thank you for the article, it's helped me get up and running with node/docker better than any other article so far. I'm brand new to Docker so a lot of this is still kind of confusing to me. Was hoping to get a few questions answered.

1) If using yarn, does it need to be installed into the Docker container first? I switched out npm with yarn in the examples you gave and it worked fine, but I don't know if it's just because I have yarn installed globally on my pc.

2) I don't really get the concept of having a Dockerfile (which you said we're supposed to set up best for both prod and dev environments) and a docker-compose file. If the docker-compose is used for dev, why does the dockerfile have to be configured for dev? I don't really understand when and how each of them are used relative to eachother.

3) While developing, do you have to continually rebuild the image as you add dependencies?

Thank you for your time and for the article, much appreciated!

Collapse
 
alex_barashkov profile image
Alex Barashkov

Hey @ohryan
1) yarn is the part of node docker image, that why it works for you
2) Actually I'm proposing try to unify Dev and prod dockerfiles if that's possible. In most of projects I worked in, they could be easily be the same
3) That's only one downside, after changing you dependencies you have to rebuild the image. Fortunately it mostly actively happens at the beginning of the project. But it always depends on your docker compose configuration, for example in my example goal was to make sure we only rely on docker on local machine, but with small changes you could change that approach to installation of node modules on local machine and then use them with docker.