Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp build into Docker container when NODE_ENV=production

I have a Docker container that host a NodeJS Web application.

This docker container has the environment variable NODE_ENV=production

When I run the container, npm install skip all the devDependencies from the package.json file because of that.

I thought 3 differents solutions but none seems good

  1. Store the build on my CVS
  2. Build outside docker
  3. Move all devDependencies to dependencies

Choice 1 take storage on CVS, and look stupid

Choice 2 require to have NodeJS, npm, gulp and many other libs installed

Choice 3 Looks the best

But i am interested in any others suggestions

like image 361
Dimitri Kopriwa Avatar asked Jul 16 '15 00:07

Dimitri Kopriwa


2 Answers

Another solution to these sorts of situations is passing NODE_ENV as a build argument:

docker build --build-arg NODE=development --rm -t some/name  .

For anyone running into issues passing NODE_ENV as a build-arg...try just passing it as NODE (as is done above) or some other name, instead. And in your Dockerfile you can use it like so:

ARG NODE=production
ENV NODE_ENV ${NODE}
RUN npm start

Note, in the code above, production is the default, but you can override it with --build-arg NODE=development.

like image 86
David Sinclair Avatar answered Oct 30 '22 17:10

David Sinclair


Ok, i found a solution !

My node APP in production require the env var NODE_ENV=production

So I've edited the docker file and removed the line

ENV NODE_ENV production

I've updated CMD to

CMD ['./start.sh']

Here is the ./start.sh

#!/bin/bash
gulp build
export NODE_ENV=production
nodemon server -p80
like image 26
Dimitri Kopriwa Avatar answered Oct 30 '22 17:10

Dimitri Kopriwa