Skip to content

Commit cde149b

Browse files
🔄 Update "How to deploy a Node.js application with Docker" (#1236)
1 parent 6f13d7b commit cde149b

File tree

1 file changed

+11
-13
lines changed
  • tutorials/deploy-nodejs-with-docker

1 file changed

+11
-13
lines changed

‎tutorials/deploy-nodejs-with-docker/01.en.md‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
SPDX-License-Identifier: MIT
33
path: "/tutorials/deploy-nodejs-with-docker"
44
slug: "deploy-nodejs-with-docker"
5-
date: "2024-09-05"
5+
date: "2025-09-02"
66
title: "How to deploy a Node.js application with Docker"
77
short_description: "Learn how to deploy a Node.js app to an Ubuntu server with Docker, Docker Hub and Docker Compose"
88
tags: ["Docker", "Deploy", "Cloud", "Lang:JS"]
@@ -45,13 +45,11 @@ This tutorial shows how to deploy a Node.js application to a cloud server throug
4545
* <kbd>package.json</kbd>
4646
```json
4747
{
48-
"version": "1.1.0",
48+
"version": "1.0.0",
49+
"private": true,
4950
"name": "myproject",
50-
"description": "Example package.json file.",
51-
"main": "src/index.js",
52-
"scripts": {
53-
"build": "echo \"Building the application\""
54-
}
51+
"description": "Example project",
52+
"main": "src/index.js"
5553
}
5654
```
5755

@@ -87,7 +85,7 @@ In case you're just getting started with Docker, here are some terms that are wo
8785
Create a file called `Dockerfile` with the following content in the root of your Node.js project directory:
8886

8987
```do
90-
FROM node:20.17
88+
FROM node:22
9189

9290
ENV NODE_ENV=production
9391

@@ -106,7 +104,7 @@ CMD [ "node", "src/index.js" ]
106104

107105
The `Dockerfile` is the place where you put the instructions that allow Docker to *build* an image. Every instruction represents the creation of a layer, which is a modification of the image file system that is being created.
108106

109-
In this case, we're composing our image by starting from a template, sometimes called the *base image*, that in this case is `node:20.17`. This is an official image provided by the Docker company, and you can find more about it [here](https://hub.docker.com/_/node).
107+
In this case, we're composing our image by starting from a template, sometimes called the *base image*, that in this case is `node:22`. This is an official image provided by the Docker company, and you can find more about it [here](https://hub.docker.com/_/node).
110108

111109
The next step sets the `NODE_ENV` environment variable to `production`. The main effect here is to avoid installing development packages when running the npm installation below, but it can often lead to better optimizations in modules you might be relying on.
112110

@@ -148,7 +146,7 @@ docker build -t myproject .
148146
149147
The `-t` option specifies the name of the image, in this case `myproject`. The `.` at the end of the line is required to tell Docker to look for a `Dockerfile` in the current directory.
150148

151-
**NOTE**: the first time that you run the build, it will take a while because Docker has to download all the layers of the base image (Node.js 20.17 in this case).
149+
**NOTE**: the first time that you run the build, it will take a while because Docker has to download all the layers of the base image (Node.js 22 in this case).
152150

153151
Since we're going to upload this image to the Docker Hub online registry (to make it accessible from our server), we need to name the image by using a specific convention.
154152

@@ -163,10 +161,10 @@ Where `username` is your Docker Hub username, and `latest` is the *tag* of the i
163161
```sh
164162
docker build -t myproject .
165163
docker tag myproject username/myproject:latest
166-
docker tag myproject username/myproject:20240905
164+
docker tag myproject username/myproject:20250902
167165
```
168166

169-
These commands build an image and then tag it with the tags `latest` and `20240904` (the date this tutorial was last updated).
167+
These commands build an image and then tag it with the tags `latest` and `20250902` (the date this tutorial was last updated).
170168

171169
Docker Hub doesn't remove old images by default, so this allows to have an history of all the images that you pushed to the registry. The image with tag `latest` will always be the one that was most recently built, while the older ones will be tagged with a date.
172170

@@ -257,7 +255,7 @@ This is a very basic Docker Compose file that configures a single container call
257255
services:
258256
myproject:
259257
container_name: 'myproject'
260-
image: 'username/myproject:20240904'
258+
image: 'username/myproject:20250902'
261259
restart: unless-stopped
262260
```
263261

0 commit comments

Comments
 (0)