I'm looking for a solution to have both a development and a production environment in my project using docker, docker-compose and nodejs.
How do I approach this?
Basically what I want is a command to start my docker production environment, and a command to start my development environment (which could use nodemon for example).
Here is my Dockerfile
FROM node:13-alpine
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN npm install
RUN npm run build
EXPOSE 1234
CMD ["npm", "run", "prod"] # <--- Have a possibility to run something like "npm run dev" here instead
docker-compose.yml
version: "3"
services:
findus:
build: .
ports:
- "1234:1234"
links:
- mongo
container_name: myapp
mongo:
image: mongo
restart: always
ports:
- "4444:4444"
package.json
// ...
"scripts": {
"build": "tsc",
"dev": "nodemon source/index.ts",
"prod": "node build/index.js"
},
// ...