Skip to content

Commit b84dc2a

Browse files
committed
patched code highlight bug with dockerfile format
1 parent 58974bc commit b84dc2a

File tree

4 files changed

+58
-22
lines changed

4 files changed

+58
-22
lines changed

src/content/12/en/part12b.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,13 @@ COPY . .
227227

228228
RUN npm ci
229229

230-
ENV DEBUG=playground:* # highlight-line
230+
#highlight-start
231+
ENV DEBUG=playground:*
232+
#highlight-end
231233

232-
CMD npm start # highlight-line
234+
#highlight-start
235+
CMD npm start
236+
#highlight-end
233237
```
234238

235239
> <i>If you're wondering what the DEBUG environment variable does, read [here](http://expressjs.com/en/guide/debugging.html#debugging-express).</i>
@@ -252,13 +256,17 @@ FROM node:20
252256

253257
WORKDIR /usr/src/app
254258

255-
COPY --chown=node:node . . # highlight-line
259+
#highlight-start
260+
COPY --chown=node:node . .
261+
#highlight-end
256262

257263
RUN npm ci
258264

259265
ENV DEBUG=playground:*
260266

261-
USER node # highlight-line
267+
#highlight-start
268+
USER node
269+
#highlight-end
262270

263271
CMD npm start
264272
```

src/content/12/en/part12c.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ RUN npm ci
105105

106106
RUN npm run build
107107

108-
RUN npm install -g serve # highlight-line
108+
#highlight-start
109+
RUN npm install -g serve
110+
#highlight-end
109111

110-
CMD ["serve", "dist"] # highlight-line
112+
#highlight-start
113+
CMD ["serve", "dist"]
114+
#highlight-end
111115
```
112116

113117
Our CMD now includes square brackets and as a result, we now use the <i>exec form</i> of CMD. There are actually **three** different forms for CMD, out of which the exec form is preferred. Read the [documentation](https://docs.docker.com/reference/dockerfile/#cmd) for more info.
@@ -125,8 +129,10 @@ With multi-stage builds, a tried and true solution like [Nginx](https://en.wikip
125129
Let's use the previous Dockerfile but change the FROM to include the name of the stage:
126130

127131
```Dockerfile
128-
# The first FROM is now a stage called build-stage
129-
FROM node:20 AS build-stage # highlight-line
132+
# El primer FROM ahora es una etapa llamada build-stage
133+
# highlight-start
134+
FROM node:20 AS build-stage
135+
# highlight-end
130136

131137
WORKDIR /usr/src/app
132138

@@ -136,12 +142,16 @@ RUN npm ci
136142

137143
RUN npm run build
138144

139-
# This is a new stage, everything before this is gone, except for the files that we want to COPY
140-
FROM nginx:1.25-alpine # highlight-line
145+
# Esta es una nueva etapa, todo lo anterior a esta linea ha desaparecido, excepto por los archivos que queremos COPIAR
146+
# highlight-start
147+
FROM nginx:1.25-alpine
148+
# highlight-end
141149

142-
# COPY the directory dist from the build-stage to /usr/share/nginx/html
143-
# The target location here was found from the Docker hub page
144-
COPY --from=build-stage /usr/src/app/dist /usr/share/nginx/html # highlight-line
150+
# COPIA el directorio dist de build-stage a /usr/share/nginx/html
151+
# El destino fue encontrado en la pagina de Docker hub
152+
# highlight-start
153+
COPY --from=build-stage /usr/src/app/dist /usr/share/nginx/html
154+
# highlight-end
145155
```
146156

147157
We have declared also <i>another stage</i>, to where only the relevant files of the first stage (the <i>dist</i> directory, that contains the static content) are copied.

src/content/12/es/part12b.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,13 @@ COPY . .
227227

228228
RUN npm ci
229229

230-
ENV DEBUG=playground:* # highlight-line
230+
#highlight-start
231+
ENV DEBUG=playground:*
232+
#highlight-end
231233

232-
CMD npm start # highlight-line
234+
#highlight-start
235+
CMD npm start
236+
#highlight-end
233237
```
234238

235239
> <i>Si te preguntas qué hace la variable de entorno DEBUG, lee [aquí](http://expressjs.com/en/guide/debugging.html#debugging-express).</i>
@@ -252,13 +256,17 @@ FROM node:20
252256

253257
WORKDIR /usr/src/app
254258

255-
COPY --chown=node:node . . # highlight-line
259+
#highlight-start
260+
COPY --chown=node:node . .
261+
#highlight-end
256262

257263
RUN npm ci
258264

259265
ENV DEBUG=playground:*
260266

261-
USER node # highlight-line
267+
#highlight-start
268+
USER node
269+
#highlight-end
262270

263271
CMD npm start
264272
```

src/content/12/es/part12c.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ RUN npm ci
105105

106106
RUN npm run build
107107

108-
RUN npm install -g serve # highlight-line
108+
#highlight-start
109+
RUN npm install -g serve
110+
#highlight-end
109111

110-
CMD ["serve", "dist"] # highlight-line
112+
#highlight-start
113+
CMD ["serve", "dist"]
114+
#highlight-end
111115
```
112116

113117
Nuestro CMD ahora incluye corchetes y, como resultado, usamos la <i> forma exec</i> de CMD. En realidad, hay **tres** formas diferentes para CMD, de las cuales se prefiere la forma exec. Lee la [documentación](https://docs.docker.com/reference/dockerfile/#cmd) para obtener más información.
@@ -126,7 +130,9 @@ Usemos el Dockerfile anterior pero cambiemos FROM para incluir el nombre de la e
126130

127131
```Dockerfile
128132
# El primer FROM ahora es una etapa llamada build-stage
129-
FROM node:20 AS build-stage # highlight-line
133+
# highlight-start
134+
FROM node:20 AS build-stage
135+
# highlight-end
130136

131137
WORKDIR /usr/src/app
132138

@@ -137,11 +143,15 @@ RUN npm ci
137143
RUN npm run build
138144

139145
# Esta es una nueva etapa, todo lo anterior a esta linea ha desaparecido, excepto por los archivos que queremos COPIAR
140-
FROM nginx:1.25-alpine # highlight-line
146+
# highlight-start
147+
FROM nginx:1.25-alpine
148+
# highlight-end
141149

142150
# COPIA el directorio dist de build-stage a /usr/share/nginx/html
143151
# El destino fue encontrado en la pagina de Docker hub
144-
COPY --from=build-stage /usr/src/app/dist /usr/share/nginx/html # highlight-line
152+
# highlight-start
153+
COPY --from=build-stage /usr/src/app/dist /usr/share/nginx/html
154+
# highlight-end
145155
```
146156

147157
Hemos declarado también <i>otra etapa</i>, de donde solo se mueven los archivos relevantes de la primera etapa (el directorio <i>dist</i>, que contiene el contenido estático).

0 commit comments

Comments
 (0)