No, you do not need to have different Dockerfile , and in fact you should avoid this.
The purpose of the docker is to send your application to an immutable, well-tested artifact (docker images) that is identical for production and testing, and even for developers.
Why? Because if you create different artifacts for testing and production, how can you guarantee that you have already tested, also works in production? you cannot, because these are two different things.
Given all this, if during testing you mean unit tests, then you can mount the source code inside the docker container and run the tests without creating any docker images. And that is wonderful. Remember that you can create an image for tests, but it is terribly slow and makes development calm and slow, which is not very good. Then, if your test passes, you can safely create the application container.
But if you mean acceptance tests that should actually run against your running application, you should create one image for your application (only one) and run the tests in another container (for example, the example of the original test case) and run the tests against this container. This obviously means that your version for your application is different for installing npm for your tests.
Hope this gives you some insight.
Boynux
source share