<p>I would do this in the <code>Dockerfile</code>, as the NextJs CLI will be a hard dependency  for the application. It should be exclusively defined in the <code>Dockerfile</code>. 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 <code>Dockerfile</code> and any changes to the NextJs version will now be an <em>image change</em> instead of an <em>application change</em>.</p>

CC BY-SA 4.0
2022-01-19T11:03:29.780Z
2022-01-19T11:03:29.780Z
Aswin Thiyagarajan
<p>I am trying to create an image using a multi-stage build for a node project. I am using <a href="https://nestjs.com/" rel="nofollow noreferrer">NestJs</a> 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.</p>
<p>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.</p>

<docker><docker-compose>
Is it good or ok or a bad practice to add Dependency via a RUN command in Dockerfile?
Soheb
# Is it good or ok or a bad practice to add Dependency via a RUN command in Dockerfile?

(Asked by: username_0 on 2022-01-19)

I am trying to create an image using a multi-stage build for a node project. I am using [NestJs](https://nestjs.com/) 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.

**Tags:** docker, docker-compose


---

## 1 answers

### Answer by username_1 on 2022-01-19. Score: 1

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*.


---

