This is a Nest Js project configured for use with Docker
$ npm install
Ensure also that Docker is installed on your work station
# development
$ npm run start:dev
or
nest start
# Debug/watch
$ npm run start:debug
# production
$ npm run build:prod
$ npm start
- Add Dockerfile
- Add docker-compose.yml
- Add unnecessary files to .gitignore
- Add .dockerignore and include the unnecessary files
- Add nodemon-docker-debug.json
- Add
"debug": "nodemon -L --config nodemon-docker-debug.json"
script to package.json - Configure VS Code for debugging the node js app with a container
# Build the image
$ docker build -t docker-nest-js:v1.0 .
# Run the image interactively
$ docker run -it -p 3000:3000 docker-nest-js:v1.0
# Build the docker image
$ docker-compose build
# Start and login to the container
$ docker-compose up -d
$ docker-compose exec app sh
# Get the container ID
$ docker ps
# View logs
$ docker logs <container id>
# Enter the container (In alpine, use sh because bash is not installed by default)
$ docker exec -it <container id> /bin/sh
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
Tutorial: https://qiita.com/rema424/items/36475ea7379e0d9c5972
Best practices: https://github.com/docker/docker-bench-security