patterndockerMinor
Is it good or ok or a bad practice to add Dependency via a RUN command in Dockerfile?
Viewed 0 times
runpracticebaddependencydockerfileviagoodcommandadd
Problem
I am trying to create an image using a multi-stage build for a node project. I am using NestJs for the project since it uses TypeScript, and if I install only production dependency in the production stage it will not install NestJs CLI. Now, NestJs CLI is required to compile all the TypeScipt code to JavaScript. Most of the people or the blogs I have read, what they do is copy the output folder (compiled code from TypeScript to JavaScript) in the production stage which I don't want to do and really don't like the idea of copying the output folder because if I run only production stage via compose or a container it will fail.
Now, I have two options, either I can move the NestJs CLI as dependencies required for production in my package.json file, or I can add NestJs CLI via a RUN command in my Dockerfile, I want to know what would be right or the best way to do it.
Now, I have two options, either I can move the NestJs CLI as dependencies required for production in my package.json file, or I can add NestJs CLI via a RUN command in my Dockerfile, I want to know what would be right or the best way to do it.
Solution
I would do this in the
Dockerfile, as the NextJs CLI will be a hard dependency for the application. It should be exclusively defined in the Dockerfile. This way we can pin a version of NextJs CLI. Another bright side to this is that all similar application can now end up having the same Dockerfile and any changes to the NextJs version will now be an image change instead of an application change.Context
StackExchange DevOps Q#15272, answer score: 1
Revisions (0)
No revisions yet.