How To Use the Node Docker Official Image
A step-by-step tutorial on how to create a Docker container using the official image of Node that will make your work process easier and more productive.
Join the DZone community and get the full member experience.Join For Free
What Is Node.js?
What Is the Node Docker Official Image?
The Node Docker Official Image comes with all the necessary components, including source code, core dependencies, tools, and libraries, to ensure that your application runs smoothly. It is designed to support various CPU architectures such as amd64, arm32v6, arm32v7, arm64v8, ppc641le, and s390x. Additionally, you have the freedom to select different tags or image versions for your project. Opting for a specific version like node:19.0.0-slim ensures that you use a stable and efficient version of Node.js.
How To Run Node in Docker
To begin with, you should download and install your preferred Docker Desktop release. Docker Desktop comprises the Docker CLI, Docker Compose, and other essential development tools. Moreover, the Docker Dashboard, which is the UI component of Docker Desktop, will assist you in managing containers and images.
Enter a Quick Pull Command
Pulling the Node DOI is the quickest way to begin. Enter this command in your terminal.
docker pull node
This grabs the default
latest Node version from Docker Hub. You can readily use this tag for testing or local development.
After the CLI completes the task, it will show a status message. Additionally, you can verify this by going to Docker Desktop. To do this, navigate to the Images tab on the left sidebar and look through the list of images. Your node image will be displayed by Docker Desktop.
Confirm That Node Is Functional and Working
Are you interested in running your newly created image as a container? If so, simply hover over the listed node image and click on the blue "Run" button. Once you do this, your Node container will generate basic log entries and operate continuously in case any requests are received.
Create Your Node Image From a Dockerfile
By building from a Dockerfile, you can have complete authority over the composition and configuration of your image, as well as your overall application. Nevertheless, Node has minimal requirements for proper functioning. To help you get started and running, here is a Dockerfile that is stripped down (using a particular, Debian-based image version):
To create your image, Docker will utilize the Node version you have selected. It is recommended to opt for node:19-bullseye as it is a reliable image that caters to various use cases. Furthermore, this version is stable and safeguards you against any new disruptive modifications that can occur with the use of the latest tags.
To build your image from a
Dockerfile, run this command:
docker build -t my-nodejs-app .
You can then run your new image by entering this command:
docker run -it --rm --name my-running-app my-nodejs-app
Opinions expressed by DZone contributors are their own.
Competing Consumers With Spring Boot and Hazelcast
Microservices With Apache Camel and Quarkus (Part 3)
Health Check Response Format for HTTP APIs
Step Into Serverless Computing