How to containerize a Node.js application

Get the sample application To get started, clone the sample application provided for this guide. Open a terminal, navigate to your preferred working directory, and run the following command to clone the repository: git clone https://github.com/docker/docker-nodejs-sample && cd docker-nodejs-sample Initialize Docker assets Navigate to the docker-nodejs-sample directory and run the docker init command in your terminal. The docker init command provides default configurations, but you’ll need to answer a few questions about your application. Use the example below as a reference to respond to the prompts from docker init, ensuring your answers match those provided. The following content should be in your docker-nodejs-sample directory: Run the application Inside the docker-nodejs-sample directory, run the following command in a terminal. docker compose up --build Press v to view in Docker Desktop and click 3000:3000. You should see a simple todo application. In the terminal, run the following command to stop the application. docker compose down Thanks for staying till the end

Mar 22, 2025 - 17:25
 0
How to containerize a Node.js application

Get the sample application

To get started, clone the sample application provided for this guide. Open a terminal, navigate to your preferred working directory, and run the following command to clone the repository:

git clone https://github.com/docker/docker-nodejs-sample && cd docker-nodejs-sample

Image description

Initialize Docker assets

Navigate to the docker-nodejs-sample directory and run the docker init command in your terminal. The docker init command provides default configurations, but you’ll need to answer a few questions about your application. Use the example below as a reference to respond to the prompts from docker init, ensuring your answers match those provided.
Image description
Image description

The following content should be in your docker-nodejs-sample directory:

Image description

Run the application

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

docker compose up --build

Image description

  • Press v to view in Docker Desktop and click 3000:3000. Image description You should see a simple todo application. Image description
  • In the terminal, run the following command to stop the application.

docker compose down

Thanks for staying till the end