Projects
ProjectsDevOps FoundationsbeginnerInfrastructure

Dockerized Web Application

Dockerfile, image, container, ports, volumes and networking.

~10 hours 6 phases
DockerLinux

Overview

Containerize a web application with a proper Dockerfile, run it with port mapping, volumes and networking, and build a small custom image.

The problem

Package a web application as a portable, secure Docker image and run it.

Why it matters

Containerization is the baseline of modern deployment.

What you'll build

  • A portable image
  • Containerised app
  • Volumes and networking

What you'll learn

  • Dockerfile
  • Images
  • Containers
  • Volumes
  • Networking

Business problem

Applications must be packaged identically across environments.

Technical problem

Build a reusable, secure image and run it with proper ports, volumes and networking.

When you're done: A secure, portable Dockerized web application.

Requirements

User requirements

  • Build an image
  • Run with port mapping
  • Persist data via volume

System requirements

  • Docker
  • An app

Functional requirements

  • Dockerfile
  • Build
  • Run with port
  • Volume
  • Network

Non-functional requirements

  • Small image
  • Non-root user

Technical requirements

  • Dockerfile
  • docker build/run
  • Volume & network

Security requirements

  • Run as non-root
  • No secrets in image

Operational requirements

  • Documented commands

Constraints

  • Docker

Success criteria

  • Image builds and runs
  • Data persists via volume
  • Runs non-root

Flows

Request Flow

  1. 1

    Browser

    User requests the application over HTTPS.

  2. 2

    CDN / DNS

    Edge routes the request to the origin.

  3. 3

    Load Balancer

    Distributes traffic across healthy app instances.

  4. 4

    Application

    Handles the request, applies business logic.

  5. 5

    Cache

    Serves fast reads for hot data.

  6. 6

    Database

    Persists data and returns results.

Project Structure

Root of the client application source.

Setup

  1. 1

    Prerequisites

    You need the tools required by Docker, Linux installed and available on your PATH.

  2. 2

    Clone project

    Clone the repository locally.

    1. Clone the repository
    git clone <your-repo-url> <project-folder>
  3. 3

    Install dependencies

    Install the project dependencies.

    1. Initialize a Node.js project
    npm init -y

    Expected

    Creates a package.json with defaults.

    If it fails

    command not found: npm

    Fix

    Install Node.js LTS from the official site, then reopen your terminal.

  4. 4

    Configure environment

    Set the environment variables documented for this project. Never commit secrets.

    1. Create the environment file
    cp .env.example .env   # then edit values
  5. 5

    Start project

    Run the development command and confirm it starts.

    1. Start the development server
    npm run dev

    Expected

    Dev server starts; watch terminal for the local URL.

    If it fails

    Port 3000 is already in use

    Fix

    Run on another port: npm run dev -- --port 3001, or stop the conflicting process.

  6. 6

    Verify

    Open the printed local URL and confirm the primary flow works.

Build Phases

0 of 6 phases complete

  1. Objective: Establish the next milestone of the operational environment.

    What changes: The project advances to the next coherent state, keeping the previous milestones working.

    Files touched

    Relevant source and configuration files for this milestone.

    Run

    1. Initialize a Node.js project
    npm init -y

    Expected

    Creates a package.json with defaults.

    If it fails

    command not found: npm

    Fix

    Install Node.js LTS from the official site, then reopen your terminal.

    Tasks

    • Implement the specific behaviour required for this milestone.
    • Verify the previous milestone still works.

    Validate: The milestone behaves as expected and does not break existing functionality.

    Common mistakes

    • • Skipping validation and moving on before confirming the milestone works.
  2. Objective: Establish the next milestone of the operational environment.

    What changes: The project advances to the next coherent state, keeping the previous milestones working.

    Files touched

    Relevant source and configuration files for this milestone.

    Run

    1. Install the docker package
    npm install docker

    Expected

    Adds docker to node_modules and package.json.

    If it fails

    npm ERR! network / EACCES

    Fix

    Check your network or run with sudo on Linux/macOS; on Windows run the terminal as Administrator.

    Tasks

    • Implement the specific behaviour required for this milestone.
    • Verify the previous milestone still works.

    Validate: The milestone behaves as expected and does not break existing functionality.

    Common mistakes

    • • Skipping validation and moving on before confirming the milestone works.
  3. Objective: Establish the next milestone of the operational environment.

    What changes: The project advances to the next coherent state, keeping the previous milestones working.

    Files touched

    Relevant source and configuration files for this milestone.

    Run

    1. Start the development server
    npm run dev

    Expected

    Dev server starts; watch terminal for the local URL.

    If it fails

    Port 3000 is already in use

    Fix

    Run on another port: npm run dev -- --port 3001, or stop the conflicting process.

    Tasks

    • Implement the specific behaviour required for this milestone.
    • Verify the previous milestone still works.

    Validate: The milestone behaves as expected and does not break existing functionality.

    Common mistakes

    • • Skipping validation and moving on before confirming the milestone works.
  4. Objective: Establish the next milestone of the operational environment.

    What changes: The project advances to the next coherent state, keeping the previous milestones working.

    Files touched

    Relevant source and configuration files for this milestone.

    Run

    1. Build the application for production
    npm run build

    Expected

    A production bundle is emitted to the output directory.

    If it fails

    Build fails with a type or syntax error

    Fix

    Read the error message, fix the referenced file, and re-run the build.

    Tasks

    • Implement the specific behaviour required for this milestone.
    • Verify the previous milestone still works.

    Validate: The milestone behaves as expected and does not break existing functionality.

    Common mistakes

    • • Skipping validation and moving on before confirming the milestone works.
  5. Objective: Establish the next milestone of the operational environment.

    What changes: The project advances to the next coherent state, keeping the previous milestones working.

    Files touched

    Relevant source and configuration files for this milestone.

    Tasks

    • Implement the specific behaviour required for this milestone.
    • Verify the previous milestone still works.

    Validate: The milestone behaves as expected and does not break existing functionality.

    Common mistakes

    • • Skipping validation and moving on before confirming the milestone works.
  6. Objective: Establish the next milestone of the operational environment.

    What changes: The project advances to the next coherent state, keeping the previous milestones working.

    Files touched

    Relevant source and configuration files for this milestone.

    Tasks

    • Implement the specific behaviour required for this milestone.
    • Verify the previous milestone still works.

    Validate: The milestone behaves as expected and does not break existing functionality.

    Common mistakes

    • • Skipping validation and moving on before confirming the milestone works.

Commands

1. Initialize a Node.js project
npm init -y

Expected

Creates a package.json with defaults.

If it fails

command not found: npm

Fix

Install Node.js LTS from the official site, then reopen your terminal.

2. Install the docker package
npm install docker

Expected

Adds docker to node_modules and package.json.

If it fails

npm ERR! network / EACCES

Fix

Check your network or run with sudo on Linux/macOS; on Windows run the terminal as Administrator.

3. Start the development server
npm run dev

Expected

Dev server starts; watch terminal for the local URL.

If it fails

Port 3000 is already in use

Fix

Run on another port: npm run dev -- --port 3001, or stop the conflicting process.

4. Build the application for production
npm run build

Expected

A production bundle is emitted to the output directory.

If it fails

Build fails with a type or syntax error

Fix

Read the error message, fix the referenced file, and re-run the build.

Testing

Unit tests

  • Core logic and pure functions behave correctly.

    npm init -y

    Success: All unit tests pass without errors.

Integration tests

  • Components integrate correctly with data sources and services.

    npm test

    Success: Integration tests pass for the primary flows.

API tests

  • Endpoints respond to valid and invalid input correctly.

    npm test

    Success: API tests cover happy and failure paths.

End-to-end tests

  • A user can complete the primary journey end to end.

    npm run test:e2e

    Success: The main user journey completes successfully.

Security tests

  • No obvious security regressions are introduced.

    npm audit

    Success: No high or critical vulnerabilities.

Debugging & Troubleshooting

Container exits immediately

Why: The process inside the container finishes or crashes on boot.

Check: Read the container logs and inspect the exit code.

docker logs <container> && docker inspect <container> --format '{{.State.ExitCode}}'

Fix: Fix the crashing entrypoint/command or run a foreground process.

Prevent: Test the image entrypoint locally before committing it.

Image build fails

Why: A build step errors — missing package, network, or syntax.

Check: Re-run the build with more output.

docker build --progress=plain -t myapp .

Fix: Resolve the failing step in the Dockerfile.

Prevent: Pin base image tags and test builds in CI.

Network failure between containers

Why: Services on different networks cannot resolve one another.

Check: Verify the compose network and service names.

docker network ls && docker network inspect <network>

Fix: Attach services to a shared network and use service names.

Prevent: Define a top-level networks section in compose.

Volume permission denied

Why: The container user cannot write to a mounted host directory.

Check: Compare UID/GID of the host directory and container user.

docker run --rm -v $(pwd)/data:/data alpine ls -ln /data

Fix: Align the container user with the host owner or adjust permissions.

Prevent: Run non-root and document required mount permissions.

Security

Security is treated as a core requirement: input is validated, secrets are protected, and dependencies are kept up to date.

  • Input validation

    Validate and sanitize all user input before use.

  • Secrets management

    Store secrets in environment variables, never in source.

  • Dependency hygiene

    Regularly audit dependencies for known vulnerabilities.

Deployment

  1. 1

    Prepare for deployment

    Build the production artifact.

    1. Build for production
    npm run build
  2. 2

    Deploy

    Deploy to the project target platform following its documented steps.

    1. Deploy
    npm run deploy   # or the platform-specific command
  3. 3

    Verify

    Confirm the deployed application responds and its health check passes.

    1. Check health
    curl -I https://<your-deployed-url>

Documentation

Project Overview

Containerize a web application with a proper Dockerfile, run it with port mapping, volumes and networking, and build a small custom image. This is a beginner infrastructure project in the operational environment space, built to demonstrate real engineering, not just copied code.

What You Will Build

- A portable image - Containerised app - Volumes and networking

Problem Statement

Applications must be packaged identically across environments. Build a reusable, secure image and run it with proper ports, volumes and networking.

Technology Stack

Docker, Linux

Installation

Clone the repository and install dependencies with the documented commands.

Local Development

Run the development command and open the printed local URL.

Testing

Run the test commands documented in the Testing section and confirm they pass.

Deployment

Follow the documented deployment steps for this project's target platform.

Interview Explanation

Use the Interview section to explain the architecture, technology choices and trade-offs.

Build Process

Phases guide the build in 6 checkpoints. Complete each and validate before moving on.

Interview Prep

30-second pitch

I built Dockerized Web Application — package a web application as a portable, secure docker image and run it. It uses Docker, Linux and solves applications must be packaged identically across environments.

2-minute walkthrough

Containerize a web application with a proper Dockerfile, run it with port mapping, volumes and networking, and build a small custom image. The core requirements were Dockerfile, Build, Run with port. I structured the work around Write a Dockerfile, Build and run images, Use volumes and networks and validated the result with the documented tests.

Architecture

Because this is a devops-foundations project, the architecture is concentrated in operational environment rather than a distributed system.

Why these technologies

I chose Docker, Linux because they are the pragmatic, well-supported tools best suited to building a infrastructure of this kind.

Why this architecture

The structure exists to keep concerns separated, make each piece testable, and scale the project cleanly as requirements grow.

At scale

At scale I would introduce caching, move to a service boundary structure, add proper observability, and enforce stricter contracts between components.

What can fail

The data source becomes unavailable, A dependency introduces a breaking change, Performance degrades under load, Configuration drift between environments

Monitoring

Monitoring is covered in the Observability section, focusing on basic health and error signals.

Security

Security was handled by validating input, protecting secrets, and following the practices listed in the Security section.

Deployment strategy

Deployment follows the steps in the Deployment section for the target platform, with a health check to confirm success.

What I'd do differently

With more time I would add deeper test coverage, stronger observability, and automated deployment.

Practice Q&A

Why did you build Dockerized Web Application?

To demonstrate Write a Dockerfile and Build and run images on a real, portfolio-worthy project.

What was the hardest part?

Coordinating the pieces so each stays correct as the project grows, and validating end to end.

How do you handle failure and scale?

By designing for correctness first and adding resilience once the core works.

Extensions

  • Add deeper test coverage
  • Add observability and alerting
  • Harden security
  • Automate deployment

Completion Checklist

Prerequisite Projects

Next Steps