DEV Community

Cover image for How to containerize a Node.js application
Olalekan Oladiran
Olalekan Oladiran

Posted on

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

Top comments (0)

👋 Kindness is contagious

If this post resonated with you, feel free to hit ❤️ or leave a quick comment to share your thoughts!

Okay