DEV Community

Cover image for Dockerizing a Node.js To-Do List and Deploying to AWS ECS
chandra penugonda
chandra penugonda

Posted on

Dockerizing a Node.js To-Do List and Deploying to AWS ECS

Building full-stack projects is a great way to learn modern development tools.

In this post, we’ll take our glassmorphic Todo List application and deploy it to the cloud using Docker, Amazon ECR, and Amazon ECS (Fargate). (code on GitHub) that uses Express . We’ll show how to build the app locally, containerize it with Docker (using a Dockerfile and Docker Compose), and then deploy it to AWS ECS (Elastic Container Service). Along the way, we’ll explain key technical concepts and steps in detail. This tutorial is aimed at developers interested in Node.js, Docker, and AWS container deployments.

The Stack

Our project is built with:

  • Express: A lightweight web framework for Node.js.
  • Vanilla JS: Managing state locally in-memory (no external database like Redis required for this simplified version).
  • CSS3: Modern glassmorphism design.

Prerequisites and Setup

  • Node.js & npm: Install Node.js (which includes npm) to run the app and manage dependencies.
  • Git: Clone the GitHub repository:
  git clone https://github.com/chandrakumarreddy/docker_node-todo-list.git
  cd docker_node-todo-list
Enter fullscreen mode Exit fullscreen mode

Once you have Node, run npm install to fetch dependencies. The project’s package.json defines the main packages: it uses Express as a lightweight web framework for Node.js. The code defines routes to add/delete to-do items, and Redis is used to persist them.

To test locally (without Docker), start the app with:

npm start
Enter fullscreen mode Exit fullscreen mode

Then visit http://localhost:3000. The Express server listens on port 3000 by default, rendering the to-do list

Containerizing the App with Docker

Next, we’ll containerize the Node.js app. A Dockerfile describes how to build a Docker image that contains the app and its runtime. For example, a typical Dockerfile might look like:

FROM node:16-alpine        # Base image with Node.js
WORKDIR /app              # Set working directory
COPY package*.json ./     # Copy package.json and package-lock.json
RUN npm install           # Install dependencies
COPY . .                  # Copy app source code
EXPOSE 3000               # Expose port
CMD ["node", "app.js"]    # Default command
Enter fullscreen mode Exit fullscreen mode

This Dockerfile starts from a small Alpine Linux Node image, copies in the app, installs its npm packages, and defines the startup command. Running docker build -t todo-app . will build the image.

After building, verify the image and run a container:

docker build -t todo-app .
docker run -p 3000:3000 todo-app
Enter fullscreen mode Exit fullscreen mode

Now the app is running in a container on port 3000.

Deploying to AWS ECS

With a Docker image ready, we can deploy to AWS ECS. ECS (Elastic Container Service) is Amazon’s way to run Docker containers at scale.

Good catch 👍 — you’re right. For a Dev.to-quality, beginner-friendly post, ECR repo creation must be explicit. Below is a drop-in replacement section you can paste into your .md file under Deploying to AWS ECS.


Push Docker Image to AWS ECR (Step-by-Step)

Before ECS can run your container, we must store the Docker image in Amazon ECR (Elastic Container Registry). ECR is AWS’s managed Docker image registry.

1. Create an ECR Repository

You can create the repository either via AWS Console or AWS CLI.

Option A: Using AWS Console (Beginner Friendly)

  1. Go to AWS Console → ECR
  2. Click Create repository
  3. Choose:
  • Visibility: Private
  • Repository name: todo-app
    1. Click Create repository
    2. Copy the Repository URI, it will look like:
   123456789012.dkr.ecr.us-east-1.amazonaws.com/todo-app
Enter fullscreen mode Exit fullscreen mode

Option B: Using AWS CLI (Recommended for Devs)

Make sure AWS CLI is configured:

aws configure
Enter fullscreen mode Exit fullscreen mode

Create the ECR repository:

aws ecr create-repository \
  --repository-name todo-app \
  --region us-east-1
Enter fullscreen mode Exit fullscreen mode

Output will include:

"repositoryUri": "123456789012.dkr.ecr.us-east-1.amazonaws.com/todo-app"
Enter fullscreen mode Exit fullscreen mode

2. Authenticate Docker with ECR

Docker must authenticate before pushing images.

aws ecr get-login-password --region us-east-1 \
| docker login \
--username AWS \
--password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

If successful, you’ll see:

Login Succeeded
Enter fullscreen mode Exit fullscreen mode

3. Build the Docker Image

From your project root:

docker build -t todo-app .
Enter fullscreen mode Exit fullscreen mode

Verify:

docker images
Enter fullscreen mode Exit fullscreen mode

4. Tag the Image for ECR

docker tag todo-app:latest \
123456789012.dkr.ecr.us-east-1.amazonaws.com/todo-app:latest
Enter fullscreen mode Exit fullscreen mode

5. Push Image to ECR

docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/todo-app:latest
Enter fullscreen mode Exit fullscreen mode

Once complete, your image will appear in the ECR console.

  1. Create an ECS Cluster

  2. Task Definition: Example JSON:

   {
     "containerDefinitions": [{
       "name": "todo-app",
       "image": "<aws_account_id>.dkr.ecr.<region>.amazonaws.com/todo-app:latest",
       "portMappings": [{"containerPort": 3000}],
       "environment": [{"name":"NODE_ENV","value":"production"}]
     }],
     "requiresCompatibilities": ["FARGATE"],
     "cpu": "256",
     "memory": "512"
   }
Enter fullscreen mode Exit fullscreen mode
  1. Create a Service: Create a new service in your cluster using the above task definition.

How It Works

The Node.js app uses Express to handle web requests and EJS to render HTML pages. When you visit /, it reads to-do items from Redis and displays them in a Bootstrap-styled page.

In Docker, the Dockerfile specifies the runtime environment. When running a container, Docker Compose sets up networking so that the Redis container and the app container communicate seamlessly.

On AWS ECS, the Fargate service pulls the Docker image and runs it in the cloud. The ECS task definition acts like our Docker Compose profile.

Conclusion

This tutorial covered building a Node.js to-do app, containerizing it with Docker, and deploying on AWS ECS Fargate.

Resources

Top comments (0)