I have a similar question to this, but slightly different, and I don't figured out how to do it.
Like in the accepted answer was said, I know that I can pass commands to a container, but my scenario is this:
// Dockerfile
FROM node:8.9
LABEL maintainer="..."
ADD . /app
WORKDIR /app
RUN npm install --production
ARG PORT=10000
EXPOSE $PORT
CMD [ "npm", "start" ]
So, I'm installing only production dependencies to the container, this way my container is lighter, but I cannot run tests in it.
Do I need another Dockerfile for testing purposes?
I thought a tricky solution for this. Using an argument, but it doesn't look a good way to solve this. The solution would be:
// docker-compose.yml
version: '3'
services:
api:
build:
context: .
args:
- PROD='--production'
- PORT
apitest:
build:
context: .
args:
- PORT
And use the PROD var in the Dockerfile
// Dockerfile
FROM node:8.9
LABEL maintainer="..."
ADD . /app
WORKDIR /app
RUN npm install $PROD
ARG PORT=10000
EXPOSE $PORT
CMD [ "npm", "start" ]
This way, only will be installed production dependencies in the api service.
Like I said, this is really tricky, so, is there an "official" or "recommended" approach that I'm not aware of? Maybe using a Dockerfile.test?