Building and Updating Docker Containers: A Practical Hands-On Guide for Beginners

Published: (December 11, 2025 at 01:56 PM EST)
3 min read
Source: Dev.to

Source: Dev.to

Introduction

In today’s fast‑paced development environment, consistency and portability are critical. Applications must run reliably across different machines, environments, or even in the cloud. Docker provides a solution by packaging your application along with its dependencies into a container, ensuring it behaves the same everywhere.

In this hands‑on guide, you’ll learn how to containerize a simple Node.js “Todo List” application. You don’t need prior experience with Node.js — the focus is on understanding how Docker builds, packages, and runs applications.

By the end of this tutorial, you’ll be able to:

  • Build a Docker image using a Dockerfile
  • Run your application inside a container
  • Expose your app to your local host
  • Understand how images, containers, and layers interact

Prerequisites

Ensure you have the following tools installed:

  • Docker Desktop (latest version)
  • Git (for cloning the sample app)
  • VS Code or another code editor

These tools allow you to build and run containers smoothly.

Step 1: Prepare the Application

Open a new folder in VS Code and name it container.

Folder view

Open a terminal in that folder.

Terminal view

Clone the sample Node.js application:

git clone https://github.com/docker/getting-started-app.git

You’ll see the following folder structure:

getting-started-app/
│── .dockerignore
│── package.json
│── README.md
│── spec/
│── src/
└── yarn.lock

Folder structure

This is the source code you will containerize.

Step 2: Create the Dockerfile

In the getting-started-app folder, create a file named Dockerfile and add:

Dockerfile example

# syntax=docker/dockerfile:1

FROM node:lts-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000

Explanation

  • FROM – selects a lightweight Node.js base image
  • WORKDIR – sets the working directory inside the container
  • COPY – transfers your source code into the container
  • RUN – installs production dependencies
  • CMD – defines the command to start the app
  • EXPOSE – documents the port the app listens on

Step 3: Build the Docker Image

Navigate to the project folder:

cd /path/to/getting-started-app

Navigate to folder

Build the image:

docker build -t getting-started .

Docker build output

What happens:

  • Docker downloads the Node.js base image (if not already present)
  • Copies your app files into the image
  • Installs dependencies
  • Packages everything into a Docker image named getting-started

Step 4: Run Your Container

Start the container:

docker run -d -p 127.0.0.1:3000:3000 getting-started

Flags explained

  • -d – runs the container in the background (detached)
  • -p HOST:CONTAINER – maps container port 3000 to your local port 3000

Visit http://127.0.0.1:3000 in your browser. Your Todo List app should be running. Add tasks, mark them complete, and see how everything works inside the container.

Step 5: Verify Running Containers

Check which containers are active:

docker ps

You’ll see the container ID, image name, port mappings, and status — confirming that your app is active.

Step 6: Update the Application

Suppose you want to change the “empty text” message to:

You have no todo items yet! Add one above!

Edit src/static/js/app.js and update line 56:

- No items yet! Add one above!
+ You have no todo items yet! Add one above!

Editing code

Rebuild the Docker image with the updated code:

docker build -t getting-started .

Start a new container using the updated image:

docker run -d -p 127.0.0.1:3000:3000 getting-started

Your changes are now reflected in the running application.

Back to Blog

Related posts

Read more »

When Reality Dissolves

In December 2024, Fei‑Fei Li held up a weathered postcard to a packed Stanford auditorium—Van Gogh’s The Starry Night, faded and creased from age. She fed it to...

Did you know? (Part 3)

Google Cloud Shell You can use Google Cloud Shell as an environment to code! It has a lot of tools for JavaScript, .NET, and more. Best of all, you can install...