-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
57 lines (29 loc) · 2.13 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
FROM node:22.3-alpine3.19
WORKDIR /app
COPY package.json .
#Here the (.) means the current directory it is same as /app Here package.json file will be copied to /app directory
#RUN npm install
#NODE_ENV is a argument which we are going to pass separately
ARG NODE_ENV
RUN if [ "$NODE_ENV" = "development" ]; \
then npm install; \
else npm install --only=production; \
fi
#Why we are copying the whole directory to app directory and whats the purpose of copying package.json separately?
#Its beacuse Docker image works in layers, It means FROM is a layer and WORKDIR is a layer and RUN is a layer,
# And all the layer is cached, so that if COPY package.json is not changed then it will skip this layer , same for RUN command
# But in last copy which copy all the files of the directory becuse we migt need to change anything in the application .
#The summary is , copying twice will give optimization When it will see there is no change in package.json then it will not copy it and comes to RUN and same for RUN and it will then come to other files and only copy other files.
#--------------------- docker ignore -------------------
#Here copy will copy all the files we have in . directory but we dont need the node_modules , same way there might be lots of files and folder we don't need. So That we can use docker ignore file which will help us to ignore the unneccessary files.
COPY . ./
#Its the port number where the server will run
ENV PORT 3000
EXPOSE $PORT
#Entry Point for the container
CMD ["node", "app.js"]
# In the context of the dev script in your package.json file, the command nodemon -L app.js will start nodemon in legacy watching mode, watching for changes to the app.js file and restarting the application when changes are detected.
#CMD [ "nodemon", "app"]
# i think this might work for global nodemon CMD [ "nodemon", "app.js"]
#NOTE: docker run -v pathtofolderlocation:pathtofolercontainer -d --name node-app -p 3000:3000 node-app-image
#docker run -v D:\BackendDevelopment\NodeDocker:/app -d --name node-app -p 3000:3000 node-app-image