Use multi-stage builds based on this image saved my life.
Example:
FROM dmcpartners/docker-mozjpeg as builder
FROM node:10-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY --from=builder /usr/local /usr/local
COPY . .
CMD [ "npm", "start" ]
Note: all binary files of mozjpeg will be located in /usr/local/bin
, e.g. /usr/local/bin/jpegtran
.