przemek-nowicki/node-express-template.ts

How do you run the docker for production build?

Closed this issue · 3 comments

It's always running in dev mode even if I make Dev: false in docker-compose file

Good question @Tasin5541, you can do it by the following commands:

  1. For the sake of readability, build an image with custom name i.e. net.ts, so go to the root project (where the Dockerfile is) and run:
    docker build -t net.ts .
  2. Execute the docker run command with all the required environment variables to create container based on net.ts image:
    docker run --rm -it -e NODE_ENV='production' -e API_KEY_TOKEN='your-api-token' net.ts

You should see the following result, if so you just ran the app in production mode.

> net.ts@1.0.0 server:prod
> node dist/server.js

2022-06-27 15:03:00 info: Logger level is set to info
2022-06-27 15:03:00 info: Aapplication listens on PORT: 8080 

btw. I will update README file about this part as it may be not clear for other folks.

Do we need to copy everything for the production build (the ts files)? Copying only the build folder and package*.json should suffice, right? This'll keep the image size low too

That's a good point, I will create a new thread for this to not mix up these two topics.