EDITED.Resolved
So I created default nest.js project with nest new project
command in terminal.
In root folder I created files:
Dockerfile
# Base image
FROM node:18-alpine AS base
WORKDIR /app
COPY package*.json ./
FROM base AS dev
# Install app dependencies
RUN npm install
# Bundle app source
COPY . .
EXPOSE 4250
CMD [ "npm", "run", "start:dev" ]
FROM base AS prod
RUN npm install
COPY . .
RUN npm run build
CMD [ "npm", "run", "start:prod" ]
docker-compose.yml
version: '3.9'
services:
app:
build:
context: .
dockerfile: Dockerfile
target: dev
ports:
- 4250:4250
volumes:
- ./src:/app/src
.dockerignore
node_modules
dist
.git
.env
docker.env
Then I ran command docker-compose up
, and as a result in CLI I have messages:
I can now test application with postman, or just open localhost:4250 in browser, yet on changes in code container does not rebuild. How to fix it?
PS. This is the most simplistic version of docker configs, I plan to build up / optimise on it, but first I need to fix problem with updates not been registered.
There is an unused block of code:
FROM base AS dev
# Install app dependencies
RUN npm install
# Bundle app source
COPY . .
EXPOSE 4250
CMD [ "npm", "run", "start:dev" ]
coment it or do the build there and copy it to the next step.
To rebuild the container do a docker-compose up --build