You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 07-cloud/03-docker/01-docker-commands/README.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,9 +86,7 @@ Docker run `pull`s images automatically if it hasn't them. Let's remove an exist
86
86
```bash
87
87
docker image rm <IMAGE NAME>:<TAG>
88
88
docker rmi <IMAGE NAME>:<TAG>
89
-
docker image prune
90
89
```
91
-
> `prune`: Remove all dangling images, that is, all images with name equals <none>. Dangling images are not referenced by other images and are safe to delete.
Copy file name to clipboardExpand all lines: 07-cloud/03-docker/02-docker-image/README.md
+20-18Lines changed: 20 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ We can create our custom images. In this case, we will use [the node image](http
17
17
_./Dockerfile_
18
18
19
19
```Docker
20
-
FROM node:20-alpine
20
+
FROM node:22-alpine
21
21
```
22
22
23
23
> You can use [Docker VSCode extension](https://code.visualstudio.com/docs/containers/overview)
@@ -27,7 +27,7 @@ Let's create the path where we are going to copy our app:
27
27
_./Dockerfile_
28
28
29
29
```diff
30
-
FROM node:20-alpine
30
+
FROM node:22-alpine
31
31
+ RUN mkdir -p /usr/app
32
32
+ WORKDIR /usr/app
33
33
@@ -58,7 +58,7 @@ Copy all files:
58
58
_./Dockerfile_
59
59
60
60
```diff
61
-
FROM node:20-alpine
61
+
FROM node:22-alpine
62
62
RUN mkdir -p /usr/app
63
63
WORKDIR /usr/app
64
64
@@ -71,7 +71,7 @@ Execute install and build:
71
71
_./Dockerfile_
72
72
73
73
```diff
74
-
FROM node:20-alpine
74
+
FROM node:22-alpine
75
75
RUN mkdir -p /usr/app
76
76
WORKDIR /usr/app
77
77
@@ -108,7 +108,7 @@ We can create some docker steps to install server and execute it:
108
108
_./Dockerfile_
109
109
110
110
```diff
111
-
FROM node:20-alpine
111
+
FROM node:22-alpine
112
112
RUN mkdir -p /usr/app
113
113
WORKDIR /usr/app
114
114
@@ -119,13 +119,13 @@ RUN npm run build
119
119
+ RUN cp -r ./dist ./server/public
120
120
+ RUN cd server && npm ci
121
121
122
-
+ CMD nodeserver/index.js
122
+
+ CMD ["node", "server/index.js"]
123
123
124
124
```
125
125
126
126
> RUN vs CMD: I don't want to run `node server` when we build the image, we want to run it when run the container.
127
127
>
128
-
> CMD VS ENTRYPOINT: https://docs.doppler.com/docs/dockerfile
128
+
> [CMD VS ENTRYPOINT](https://codewithyury.com/docker-run-vs-cmd-vs-entrypoint/)
129
129
130
130
Run the container:
131
131
@@ -134,9 +134,9 @@ docker build -t my-app:1 .
134
134
docker images
135
135
136
136
```
137
-
> It creates a <none> image due to replace same tag.
137
+
> In earlier versions of Docker when you re-use the same tag, it will create a new image with the same tag, but with a different ID. This is called a dangling image and you can remove it with `docker image prune`
138
138
>
139
-
> We can remove it with `docker image prune`
139
+
> But in the latest versions of Docker, it will delete the old image for you.
140
140
141
141
Run new container:
142
142
@@ -167,7 +167,7 @@ _./Dockerfile_
167
167
...
168
168
169
169
+ ENV PORT=8083
170
-
CMD nodeserver/index.js
170
+
CMD ["node", "server/index.js"]
171
171
172
172
```
173
173
@@ -196,12 +196,10 @@ If we check `docker images` we can see dangling images, due to use same tags for
196
196
197
197
```bash
198
198
docker images
199
-
docker image prune
200
-
docker images
201
199
202
200
```
203
201
204
-
On the other hand, we have an image with `~382MB`, too much size isn't it?. We should use [multi-stage builds](https://docs.docker.com/develop/develop-images/multistage-build/) to decrease this size, with only the necessary info:
202
+
On the other hand, we have an image with `~592MB`, too much size isn't it?. We should use [multi-stage builds](https://docs.docker.com/develop/develop-images/multistage-build/) to decrease this size, with only the necessary info:
205
203
206
204
> Change container project structure:
207
205
@@ -225,8 +223,8 @@ On the other hand, we have an image with `~382MB`, too much size isn't it?. We s
225
223
_./Dockerfile_
226
224
227
225
```diff
228
-
- FROM node:20-alpine
229
-
+ FROM node:20-alpine AS base
226
+
- FROM node:22-alpine
227
+
+ FROM node:22-alpine AS base
230
228
RUN mkdir -p /usr/app
231
229
WORKDIR /usr/app
232
230
@@ -247,12 +245,12 @@ RUN npm run build
247
245
+ RUN npm ci --omit=dev
248
246
249
247
ENV PORT=8083
250
-
- CMD nodeserver/index.js
251
-
+ CMD nodeindex.js
248
+
- CMD ["node", "server/index.js"]
249
+
+ CMD ["node", "index.js"]
252
250
253
251
```
254
252
255
-
> We could use `npm ci` instead of `npm install`if we have a `package-lock.json` generated.
253
+
> We can use `npm ci` instead of `npm install`because we have a `package-lock.json` generated.
0 commit comments