Skip to content

Commit e49350b

Browse files
committed
feat(dockerize): create dockerfile for nest server
1 parent ccaaf65 commit e49350b

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:10
2+
3+
# Create app directory
4+
WORKDIR /usr/src/app
5+
6+
# A wildcard is used to ensure both package.json AND package-lock.json are copied
7+
COPY package*.json ./
8+
9+
# Install necessary tools for bcrypt to run in docker before npm install
10+
RUN apt-get update && apt-get install -y build-essential && apt-get install -y python
11+
12+
# Install app dependencies
13+
RUN npm install
14+
15+
COPY . .
16+
17+
EXPOSE 3000
18+
CMD [ "npm", "run", "start:prod" ]

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* [Prisma Setup](#prisma-setup)
55
* [Start NestJS Server](#start-nestjs-server)
66
* [Rest Api](#rest-api)
7+
* [Docker](#docker)
78
* [Update Schema](#update-schema)
89
* [Graphql Client](#graphql-client)
910

@@ -72,6 +73,35 @@ Playground for the NestJS Server is available here: http://localhost:3000/graphq
7273

7374
[RESTful API](http://localhost:3000/api) documentation available with Swagger.
7475

76+
## Docker
77+
Nest serve is a Node.js application and it is easily [dockerized](https://nodejs.org/de/docs/guides/nodejs-docker-webapp/).
78+
79+
See the [Dockerfile](./Dockerfile) on how to build a Docker image of your Nest server.
80+
81+
There is one thing to be mentioned. A library called bcrypt is used for password hashing in the nest server starter. However, the docker container keeped crashing and the problem was bcrypt was missing necessary tools for compilation. The [solution](https://stackoverflow.com/a/41847996) is to install these tools for bcrypt's compilation before `npm install`:
82+
83+
```Dockerfile
84+
# Install necessary tools for bcrypt to run in docker before npm install
85+
RUN apt-get update && apt-get install -y build-essential && apt-get install -y python
86+
```
87+
88+
Now to build a Docker image of your own Nest server simply run:
89+
90+
```bash
91+
# give your docker image a name
92+
docker build -t <your username>/nest-prisma-server .
93+
# for example
94+
docker build -t nest-prisma-server .
95+
```
96+
97+
After Docker build your docker image you are ready to start up a docker container running the nest server:
98+
99+
```bash
100+
docker run -d -t -p 3000:3000 nest-prisma-server
101+
```
102+
103+
Now open up [localhost:3000](http://localhost:3000) to verify that your nest server is running.
104+
75105
## Update Schema
76106

77107
### Prisma - Database Schema

run.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
docker build -t nest-prisma-server .
2+
docker run -d -t -p 3000:3000 nest-prisma-server

0 commit comments

Comments
 (0)