Dimitri Kopriwa
Dimitri Kopriwa

Reputation: 14425

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

Upvotes: 6

Views: 6382

Answers (2)

Dimitri Kopriwa
Dimitri Kopriwa

Reputation: 14425

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

Upvotes: 5

David Sinclair
David Sinclair

Reputation: 4437

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.

Upvotes: 12

Related Questions