diff --git a/SB02-docker-build/repo/.dockerignore b/SB02-docker-build/repo/.dockerignore new file mode 100644 index 0000000..e8f765d --- /dev/null +++ b/SB02-docker-build/repo/.dockerignore @@ -0,0 +1,13 @@ +# Commmon +**/.git +**/.gitignore +**/README.md +**/.idea +**/.vscode +**/*.log + +# NodeJs Specific +**/node_modules + +# Project Specific +.next diff --git a/SB02-docker-build/repo/Dockerfile b/SB02-docker-build/repo/Dockerfile index bac701a..0c0e05e 100644 --- a/SB02-docker-build/repo/Dockerfile +++ b/SB02-docker-build/repo/Dockerfile @@ -1,18 +1,37 @@ -FROM node:12 +# Use a more specific version for your production containers can help resolve issues +FROM node:12.18.1-alpine3.12 as FirstStage # Create app directory WORKDIR /usr/src/app # Installing dependencies -COPY package*.json ./ +COPY package.json yarn.lock ./ -RUN npm install +# Should use same package management as same as your development workflow +# The dependencies lock file is critical for reproduce to same behaviour +RUN yarn install --frozen-lockfile + +# Copying Assets files +COPY public ./public # Copying source files -COPY . . +COPY pages ./pages + +# 1. Building app +# 2. Remove Dev Dependencies +RUN yarn build \ + && yarn install --production --frozen-lockfile --offline + +# Final Stage +FROM node:12.18.1-alpine3.12 + +WORKDIR /usr/src/app + +# Copy all files from builder +COPY --from=FirstStage /usr/src/app /usr/src/app -# Building app -RUN npm run build +# This don't actually publish the port but to give better documentation to your DevOps colleagues +EXPOSE 3000 # Running the app -CMD [ "npm", "start" ] +CMD [ "yarn", "start" ]