dockersamples/docker-swarm-visualizer

Should we removes the dev dependencies from the docker image?

herloct opened this issue · 1 comments

I think we should removes the dev dependencies from the docker image. It could saves around 100MB on the image sizes (from 370MB to 230MB).

We could change this parts:

# Install dependencies
RUN npm install --unsafe-perm=true

# Add the rest of the sources
ADD . /app

# Build the app
RUN npm run dist

To something like this:

# Only add those files we need at runtime
ADD ./cfg/* /app/cfg/
ADD ./dist/* /app/dist/
ADD ./node_modules/* /app/node_modules/
ADD ./src/* /app/src/
ADD ./create-index.js /app
ADD ./index.tpl /app
ADD ./server.js /app

And use something like TravisCI to run the npm run dist before building the docker image.

Thanks for the suggestion. I updated the Dockerfile as a multi-stage build file, and copied file files as you suggested. Biggest savings though was in switching to node:8.2.1-alpine. Try it out, and if you have other suggestions please do share, I'm not a node expert. Final image size is 148mb, compared to 151mb with a non-multi-stage build but still using node:8.2.1-alpine.