Last active
May 25, 2021 01:36
-
-
Save teyfix/cfb6923be8663217bf353a5b38570610 to your computer and use it in GitHub Desktop.
Docker setup for NestJS applications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# just adding the .env.local file for | |
# my local development purposes and | |
# I do not really need to specify | |
# every single file to be ignored | |
# because I am not copying everything | |
# with "COPY . ." command | |
# you can see what I mean below | |
# in "Dockerfile" | |
.env.local* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PORT=8080 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.7" | |
services: | |
app: | |
build: | |
# referencing to ./Dockerfile | |
context: . | |
volumes: | |
# mirroring only my local ./src directory | |
# into the container's so every change | |
# I have made locally will be applied | |
# inside the container too | |
- ./src:/app/src | |
ports: | |
# exposing node.js debugging port | |
# so I can debug the application with | |
# my IDE inside container | |
- 9229:9229 | |
# exposing http port so I can access the | |
# application outside of the container | |
- ${PORT}:${PORT} | |
command: npm run start:dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fetching LTS node.js image | |
FROM node:lts-alpine | |
# setting cwd to /app | |
# we will mirror the project structure to | |
# the /app directory inside container | |
WORKDIR /app | |
# copying package files before npm install | |
# this part should be seperated to help | |
# docker to cache "npm i" command | |
COPY package*.json ./ | |
# no need to explain i guess | |
RUN npm i | |
# copying the rest of the sources | |
# that is required by the application | |
# instead of this, you can simply run: | |
# COPY . . | |
# but, I just do not want to fill either | |
# the container and the .dockerignore | |
# with redundant stuff | |
COPY src ./src | |
COPY .env* ./ | |
COPY nest-cli.json ./ | |
COPY tsconfig*.json ./ | |
# finally running build before | |
# starting the application | |
RUN npm run build | |
# again, no need to explain | |
CMD ['npm', 'start'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment