Update Dockerfile to make image smaller
- Added multistaged build - Moved production depedencies to final stage - Added more verbose output during build
This commit is contained in:
parent
77e7df7b83
commit
12210a1bf5
1 changed files with 25 additions and 5 deletions
30
Dockerfile
30
Dockerfile
|
@ -1,8 +1,12 @@
|
|||
FROM node:10.14-alpine
|
||||
# Mutistaged Node.js Build
|
||||
FROM node:10-alpine as builder
|
||||
|
||||
RUN apk add --update pwgen netcat-openbsd python make gcc git g++ bash imagemagick
|
||||
# Install system dependencies
|
||||
RUN set -ex; \
|
||||
apk add --update --no-cache \
|
||||
make gcc g++ git
|
||||
|
||||
# First install dependencies
|
||||
# Copy package.json dependencies
|
||||
COPY server/package.json /app/server/package.json
|
||||
COPY server/package-lock.json /app/server/package-lock.json
|
||||
COPY client/package.json /app/client/package.json
|
||||
|
@ -14,13 +18,29 @@ COPY zone-mta/package-lock.json /app/zone-mta/package-lock.json
|
|||
|
||||
WORKDIR /app/
|
||||
|
||||
RUN for idx in client shared server zone-mta; do (cd $idx && npm install); done
|
||||
# Install dependencies in each directory
|
||||
RUN set -ex; \
|
||||
for idx in client shared server zone-mta; do (cd $idx && npm install); done
|
||||
|
||||
# Later, copy the app files. That improves development speed as buiding the Docker image will not have
|
||||
# to download and install all the NPM dependencies every time there's a change in the source code
|
||||
COPY . /app
|
||||
|
||||
RUN cd client && npm run build
|
||||
RUN set -ex; \
|
||||
cd client && \
|
||||
npm run build
|
||||
|
||||
# Final Image
|
||||
FROM node:10-alpine
|
||||
|
||||
WORKDIR /app/
|
||||
|
||||
# Install system dependencies
|
||||
RUN set -ex; \
|
||||
apk add --update --no-cache \
|
||||
pwgen netcat-openbsd bash imagemagick
|
||||
|
||||
COPY --from=builder /app/ /app/
|
||||
|
||||
EXPOSE 3000 3003 3004
|
||||
ENTRYPOINT ["bash", "/app/docker-entrypoint.sh"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue