Skip to content

Commit 273d688

Browse files
dvdksncodex
andcommitted
docs: clarify Node.js Dockerfile location (fixes #25185)
The Node.js containerize guide told readers to create a Dockerfile without saying where it belongs. Clarify that both Dockerfile options should be created in the project root and clean up existing lint failures in the touched file. Co-Authored-By: Codex <codex@openai.com>
1 parent 76547a8 commit 273d688

1 file changed

Lines changed: 34 additions & 27 deletions

File tree

content/guides/nodejs/containerize.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ aliases:
1717
Before you begin, make sure the following tools are installed and available on your system:
1818

1919
- You have installed the latest version of [Docker Desktop](/get-started/get-docker.md).
20-
- You have a [git client](https://git-scm.com/downloads). The examples in this section use a command-line based git client, but you can use any client.
20+
- You have a [Git client](https://git-scm.com/downloads). The examples in this section use a command-line based Git client, but you can use any client.
2121

2222
> **New to Docker?**
2323
> Start with the [Docker basics](/get-started/docker-concepts/the-basics/what-is-a-container.md) guide to get familiar with key concepts like images, containers, and Dockerfiles.
@@ -40,7 +40,7 @@ By the end of this guide, you will:
4040

4141
Clone the sample application to use with this guide. Open a terminal, change
4242
directory to a directory that you want to work in, and run the following command
43-
to clone the git repository:
43+
to clone the Git repository:
4444

4545
```console
4646
$ git clone https://github.com/kristiyan-velkov/docker-nodejs-sample
@@ -70,6 +70,7 @@ Choosing DHI offers the advantage of a production-ready image that is lightweigh
7070
Docker Hardened Images (DHIs) are available for Node.js in the [Docker Hardened Images catalog](https://hub.docker.com/hardened-images/catalog/dhi/node). Docker Hardened Images are freely available to everyone with no subscription required. You can pull and use them like any other Docker image after signing in to the DHI registry. For more information, see the [DHI quickstart](/dhi/get-started/) guide.
7171

7272
1. Sign in to the DHI registry:
73+
7374
```console
7475
$ docker login dhi.io
7576
```
@@ -79,7 +80,7 @@ Docker Hardened Images (DHIs) are available for Node.js in the [Docker Hardened
7980
$ docker pull dhi.io/node:24-alpine3.22-dev
8081
```
8182

82-
Create a file named `Dockerfile` with the following contents. The `FROM` instruction uses `dhi.io/node:24-alpine3.22-dev` as the base image.
83+
Create a file named `Dockerfile` in your project root with the following contents. The `FROM` instruction uses `dhi.io/node:24-alpine3.22-dev` as the base image.
8384

8485
```dockerfile
8586
# ========================================
@@ -225,7 +226,7 @@ CMD ["npm", "run", "test:coverage"]
225226
{{< /tab >}}
226227
{{< tab name="Using the Docker Official Image" >}}
227228

228-
Create a file named `Dockerfile` with the following contents:
229+
Create a file named `Dockerfile` in your project root with the following contents:
229230

230231
```dockerfile
231232
# ========================================
@@ -369,11 +370,13 @@ USER nodejs
369370
# Run tests with coverage
370371
CMD ["npm", "run", "test:coverage"]
371372
```
373+
372374
{{< /tab >}}
373375

374376
{{< /tabs >}}
375377

376378
Key features of this Dockerfile:
379+
377380
- Multi-stage structure — Separate stages for dependencies, build, development, production, and testing to keep each phase clean and efficient.
378381
- Lean production image — Optimized layering reduces size and keeps only what’s required to run the app.
379382
- Security-minded setup — Uses a dedicated non-root user and excludes unnecessary packages.
@@ -403,18 +406,18 @@ services:
403406
target: development
404407
container_name: todoapp-dev
405408
ports:
406-
- '${APP_PORT:-3000}:3000' # API server
407-
- '${VITE_PORT:-5173}:5173' # Vite dev server
408-
- '${DEBUG_PORT:-9229}:9229' # Node.js debugger
409+
- "${APP_PORT:-3000}:3000" # API server
410+
- "${VITE_PORT:-5173}:5173" # Vite dev server
411+
- "${DEBUG_PORT:-9229}:9229" # Node.js debugger
409412
environment:
410413
NODE_ENV: development
411-
DOCKER_ENV: 'true'
414+
DOCKER_ENV: "true"
412415
POSTGRES_HOST: db
413416
POSTGRES_PORT: 5432
414417
POSTGRES_DB: todoapp
415418
POSTGRES_USER: todoapp
416-
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD:-todoapp_password}'
417-
ALLOWED_ORIGINS: '${ALLOWED_ORIGINS:-http://localhost:3000,http://localhost:5173}'
419+
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:-todoapp_password}"
420+
ALLOWED_ORIGINS: "${ALLOWED_ORIGINS:-http://localhost:3000,http://localhost:5173}"
418421
volumes:
419422
- ./src:/app/src:ro
420423
- ./package.json:/app/package.json
@@ -430,8 +433,8 @@ services:
430433
path: ./src
431434
target: /app/src
432435
ignore:
433-
- '**/*.test.*'
434-
- '**/__tests__/**'
436+
- "**/*.test.*"
437+
- "**/__tests__/**"
435438
- action: rebuild
436439
path: ./package.json
437440
- action: sync
@@ -457,27 +460,27 @@ services:
457460
target: production
458461
container_name: todoapp-prod
459462
ports:
460-
- '${PROD_PORT:-8080}:3000'
463+
- "${PROD_PORT:-8080}:3000"
461464
environment:
462465
NODE_ENV: production
463466
POSTGRES_HOST: db
464467
POSTGRES_PORT: 5432
465468
POSTGRES_DB: todoapp
466469
POSTGRES_USER: todoapp
467-
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD:-todoapp_password}'
468-
ALLOWED_ORIGINS: '${ALLOWED_ORIGINS:-https://yourdomain.com}'
470+
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:-todoapp_password}"
471+
ALLOWED_ORIGINS: "${ALLOWED_ORIGINS:-https://yourdomain.com}"
469472
depends_on:
470473
db:
471474
condition: service_healthy
472475
restart: unless-stopped
473476
deploy:
474477
resources:
475478
limits:
476-
memory: '${PROD_MEMORY_LIMIT:-2G}'
477-
cpus: '${PROD_CPU_LIMIT:-1.0}'
479+
memory: "${PROD_MEMORY_LIMIT:-2G}"
480+
cpus: "${PROD_CPU_LIMIT:-1.0}"
478481
reservations:
479-
memory: '${PROD_MEMORY_RESERVATION:-512M}'
480-
cpus: '${PROD_CPU_RESERVATION:-0.25}'
482+
memory: "${PROD_MEMORY_RESERVATION:-512M}"
483+
cpus: "${PROD_CPU_RESERVATION:-0.25}"
481484
security_opt:
482485
- no-new-privileges:true
483486
read_only: true
@@ -495,16 +498,20 @@ services:
495498
image: postgres:18-alpine
496499
container_name: todoapp-db
497500
environment:
498-
POSTGRES_DB: '${POSTGRES_DB:-todoapp}'
499-
POSTGRES_USER: '${POSTGRES_USER:-todoapp}'
500-
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD:-todoapp_password}'
501+
POSTGRES_DB: "${POSTGRES_DB:-todoapp}"
502+
POSTGRES_USER: "${POSTGRES_USER:-todoapp}"
503+
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:-todoapp_password}"
501504
volumes:
502505
- postgres_data:/var/lib/postgresql
503506
ports:
504-
- '${DB_PORT:-5432}:5432'
507+
- "${DB_PORT:-5432}:5432"
505508
restart: unless-stopped
506509
healthcheck:
507-
test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER:-todoapp} -d ${POSTGRES_DB:-todoapp}']
510+
test:
511+
[
512+
"CMD-SHELL",
513+
"pg_isready -U ${POSTGRES_USER:-todoapp} -d ${POSTGRES_DB:-todoapp}",
514+
]
508515
interval: 10s
509516
timeout: 5s
510517
retries: 5
@@ -580,8 +587,8 @@ The `.dockerignore` file tells Docker which files and folders to exclude when bu
580587
> [!NOTE]
581588
> This helps:
582589
>
583-
> - Reduce image size
584-
> - Speed up the build process
590+
> - Reduce image size
591+
> - Speed up the build process
585592
> - Prevent sensitive or unnecessary files (like `.env`, `.git`, or `node_modules`) from being added to the final image.
586593
>
587594
> To learn more, visit the [.dockerignore reference](/reference/dockerfile.md#dockerignore-file).
@@ -695,7 +702,7 @@ If the build was successful, you should see `docker-nodejs-sample` image listed.
695702

696703
## Run the containerized application
697704

698-
In the previous step, you created a Dockerfile for your Node.js application and built a Docker image using the docker build command. Now it’s time to run that image in a container and verify that your application works as expected.
705+
In the previous step, you created a Dockerfile for your Node.js application and built a Docker image using the `docker build` command. Now it’s time to run that image in a container and verify that your application works as expected.
699706

700707
Inside the `docker-nodejs-sample` directory, run the following command in a terminal.
701708

0 commit comments

Comments
 (0)