HackIndia Logo
HackathonsNewsSkillsGrowth
HackIndia LogoContact: +91 9910125804

General

  • Companies
  • Colleges
  • Board of Advisors
  • Brand Ambassadors
  • FAQ
  • Contact
  • Report a Bug

Hackathons

  • Upcoming Hackathons
  • Judges
  • Mentors
  • Partners
  • Participating Colleges
  • Testimonials

Resources

  • About Us
  • Branding
  • Latest News
  • Growth
  • Skills
  • Builders
  • Ecosystem
  • Forum
  • Ideas
  • Prompt Optimizer
  • Games

© 2026 HackIndia. All rights reserved.

Privacy PolicyTerms of ServiceCode of ConductSitemap

Build 2.139 · 05 Nov 2026, 10:27 UTC

    HackIndia
    HackathonsNewsInternshipsSkillsGrowthPro Perks
    ← Dockerize a Web App

    All the reading

    Docker

    7 lessons, about 28 minutes. The check's questions come from these.

    Contents
    Docker setup and files
    1. 1. Why Docker Fixes Setup Pain
    2. 2. Write Your First Dockerfile
    Building and running images
    1. 3. Build And Run Your Image
    2. 4. Keep Data With Volumes
    Compose, data, and secrets
    1. 5. Add Compose For App Plus Database
    2. 6. Handle Environment Variables Safely
    3. 7. Make The Repo Recruiter-Ready

    Docker setup and files

    1. Why Docker Fixes Setup Pain

    4 min

    In 30 seconds
    • Explain why Docker reduces setup pain for web app projects.
    • Know what Dockerfile, image, container, and Compose each do.
    • Start a repo checklist so another builder can run your app later.

    The setup problem

    You build a web app on your laptop. It runs because your machine has the right Node, Python, Java, database client, environment variables, and port settings.

    Then your teammate clones it in hostel Wi-Fi before a hackathon demo. It fails. Their laptop has a different version, missing package, or no database running.

    Key point

    One idea

    Docker makes your app’s running setup explicit. Instead of saying “install some things and try npm start”, you describe the OS-level environment, dependencies, ports, variables, storage, and start command.

    What Docker adds

    A Dockerfile is a text file with commands used to assemble an image. The image is the packaged version of your app setup.

    A container is a running copy of that image. If the image is built the same way, the app has a much better chance of running the same way on another laptop.

    Example

    Plain project story

    Without Docker, your README may depend on hidden local setup. With Docker, the important setup starts moving into files that a reviewer can run.

    You will write the real Dockerfile in the next lesson. For now, notice the shape: choose a base, set a folder, copy code, install dependencies, start the app.

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

    Where Compose fits

    Most useful web apps need more than one process. For example, your app plus Postgres. Docker Compose is used to run these services together from one Compose file.

    2. Write Your First Dockerfile

    4 min

    In 30 seconds
    • Write a simple Dockerfile for one web app.
    • Know what FROM, WORKDIR, COPY, RUN, EXPOSE, and CMD do.
    • Add a Dockerfile that a reviewer can build later.
    Key point

    One mental model

    A Dockerfile is a recipe for your app image. It starts from a base image, adds your app files, installs dependencies, documents the port, and sets the start command.

    What goes inside

    Docker reads the Dockerfile from top to bottom. Each line should make the app closer to being runnable on another laptop.

    For a beginner web app, keep it boring. Pick the runtime image, set a working folder, copy files, install packages, and set the command that starts the server.

    Example

    Node app example

    Use this shape for a basic Node app. Change the start file or command to match your project.

    The first line asks Docker BuildKit to use the current stable Dockerfile syntax. The FROM line must come before normal build instructions.

    # syntax=docker/dockerfile:1
    FROM node:22-alpine
    
    WORKDIR /app
    
    COPY . .
    
    RUN yarn install --production
    
    EXPOSE 3000
    
    CMD ["node", "./src/index.js"]

    Building and running images

    3. Build And Run Your Image

    4 min

    In 30 seconds
    • Build an image from your Dockerfile and give it a clear name.
    • Run that image as a container and publish the app port to your laptop.
    • Debug the first failures using logs, port checks, and rebuilds.
    Key point

    One loop

    The loop is: build an image, run a container, open the app, fix errors, rebuild. Your Dockerfile is not proven until the app works from the image on your laptop.

    An image is the packaged app. A container is a running copy of that image.

    Your to-do

    Build the image

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Compose, data, and secrets

    5. Add Compose For App Plus Database

    4 min

    In 30 seconds
    • Connect your app container to a database container with Docker Compose.
    • Publish only the app port to your laptop, not the database port.
    • Run the full local stack with the modern docker compose command.
    Key point

    One file, two services

    Compose is for running a small stack, not just one container. In this lesson, your stack has an app service built from your Dockerfile and a database service pulled from an image.

    The app talks to the database by service name, like db. Compose creates the network for you.

    What Compose adds

    Your Dockerfile says how to build your app image. compose.yaml says which containers run together, which ports are published, and which volumes keep data.

    Use docker compose, with a space. Older tutorials may show docker-compose with a hyphen. Treat that as old style.

    Example

    Basic compose file

    This example is for a Node app and Postgres. Change the app port, command, and database variables to match your project.

    10 questions, 7 to pass.

    Sign in to take the test

    Current Docker teaching uses the integrated command form: docker compose. Older tutorials may show docker-compose with a hyphen. Treat that as old style when you are learning today.

    Common mistake

    Common wrong belief

    Docker is not just for final deployment. It is also for local development, judging, internships, and team projects where someone else must run your app quickly.

    Another mistake is thinking Docker removes the need for a README. It does not. A good repo still tells the reviewer what file to create and what one command to run.

    Tip

    Use AI carefully

    You can ask ChatGPT, Gemini, or Claude to draft a Dockerfile explanation for your stack. Give it your package manager, start command, app port, and database choice.

    Check the answer. It should not use old docker-compose commands as the main path. It should not hardcode secrets. It should explain which port the app listens on.

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Your to-do

    Read each line

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 6 done

    Common mistake

    EXPOSE is not publish

    EXPOSE does not make your app visible on your laptop by itself. It only documents the container port.

    Port publishing happens later when you run the container, and in this track you will handle it properly with Compose. Do not treat EXPOSE as a magic network switch.

    Tip

    Ask AI carefully

    You can ask ChatGPT, Gemini, or Claude to draft a Dockerfile for your exact stack. Paste your package file, start command, app port, and folder structure.

    Check what it returns. The Dockerfile should start with FROM, install dependencies, copy the app, include the real port, and use your actual start command. Do not accept random ports or commands.

    Prompt:
    Create a beginner Dockerfile for this web app.
    Stack: Node.js
    Package manager: yarn
    Start command: node ./src/index.js
    App listens on port: 3000
    Files: package.json, yarn.lock, src/index.js
    Keep it simple for local hackathon review.
    Common mistake

    Do not hide secrets

    Do not put database passwords, API keys, or UPI/payment keys in the Dockerfile with ENV. ENV values stay in the image metadata and can be inspected later.

    For now, leave secrets out. A later lesson will show how to handle environment variables safely with Compose and an example env file.

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    docker build -t campus-events .
    Example

    Run a web app

    Most web apps listen on a port inside the container. Your browser needs a host port on your laptop mapped to that container port.

    This example maps laptop port 3000 to container port 3000. Change the port if your app uses 5000, 8000, or 8080.

    docker run --name campus-events-web -p 3000:3000 campus-events
    
    # Then open:
    # http://localhost:3000

    What port mapping means

    The left side is the host port. That is the port on your laptop. The right side is the container port. That is where the app listens inside Docker.

    If you use -p 8080:3000, you open http://localhost:8080, even though the app inside the container still listens on 3000.

    docker run -p 8080:3000 campus-events
    Tip

    Name your container

    Use --name while learning. It makes logs and cleanup easier because you do not need to copy a random container ID.

    If you run the same name twice, Docker will complain. Remove the old container or choose a new name.

    docker logs campus-events-web
    
    docker rm campus-events-web
    Common mistake

    Rebuild after changes

    Changing your app files does not magically change an image you already built. The image is a snapshot made at build time.

    If you edit code, dependencies, or the Dockerfile, build again before you run again.

    docker build -t campus-events .
    docker run --name campus-events-web -p 3000:3000 campus-events
    Your to-do

    Debug first failures

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    docker logs campus-events-web
    
    docker ps -a
    
    docker rm campus-events-web
    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    docker build -t your-project-name .
    docker run --name your-project-web -p 3000:3000 your-project-name

    4. Keep Data With Volumes

    4 min

    In 30 seconds
    • Keep database or upload data after a container is removed.
    • Choose named volumes for app data that should survive rebuilds.
    • Avoid accidentally hiding files with the wrong mount path.

    Why data disappears

    A container is meant to be replaceable. If you remove it, anything written only inside that container can go with it.

    That is fine for code. It is bad for a database, uploaded images, SQLite files, or generated reports you need after a restart.

    Key point

    The core idea

    Use a volume when data must outlive a container. The image gives the app its starting files; the volume keeps changing data outside the container lifecycle.

    What volumes hold

    A volume can store database files, user uploads, cache files, or local development data. For your hackathon repo, it matters most for the database.

    Without a volume, your reviewer may run the app, create test data, restart containers, and lose everything. That looks broken even if your app code is fine.

    Example

    Compose volume shape

    You will build the full app plus database Compose file in the next lesson. For now, read the volume part.

    This example uses a named volume called pgdata and mounts it where the database stores its files.

    services:
      db:
        image: postgres
        volumes:
          - pgdata:/var/lib/postgresql/data
    
    volumes:
      pgdata:

    Named versus host path

    Compose volumes can mount named volumes or host paths into service containers. Named volumes are usually easier for a shared college project because Docker manages the storage location.

    Host paths are useful when you want a local folder from your laptop visible inside the container, like live source code during development. They are easier to mess up across Windows, macOS, and Linux laptops.

    Common mistake

    Mounting over app files

    A common beginner mistake is mounting a volume onto the same folder where your image copied the app code. The mount can hide the files already in the image.

    Mount data folders only. For example, mount a database data directory or uploads directory, not the whole app folder unless you know why.

    Tip

    Prefer clear names

    Name volumes after what they store, not after the tool. pgdata, mongo-data, uploads, and redis-data are easier to review than data1.

    In current Compose files, reusable volumes should also be declared in the top-level volumes section. Older examples may skip this or include an old top-level version field; you do not need that version field in current Compose examples.

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Current Compose examples start directly with services. You do not need a top-level version field.

    services:
      app:
        build: .
        ports:
          - "127.0.0.1:3000:3000"
        environment:
          DATABASE_URL: "postgres://appuser:apppassword@db:5432/appdb"
        depends_on:
          - db
    
      db:
        image: postgres:16
        environment:
          POSTGRES_USER: appuser
          POSTGRES_PASSWORD: apppassword
          POSTGRES_DB: appdb
        volumes:
          - db_data:/var/lib/postgresql/data
    
    volumes:
      db_data:
    Your to-do

    Run the stack

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Tip

    Publish the app only

    ports publishes a container port to your laptop. expose only makes a port reachable to other services inside the Compose network.

    For a local hackathon project, publish the app port. Do not publish the database port unless you really need to connect from a desktop database tool.

    Common mistake

    Do not expose publicly

    A port like "3000:3000" binds to all interfaces. On a normal college laptop this is usually fine, but on a cloud VM with a public IP it can expose the app to the internet.

    For local review, prefer "127.0.0.1:3000:3000". It binds the app to your own machine.

    Keep database data

    The db_data volume keeps Postgres files outside the database container. If the container is recreated, your local data can remain.

    Reusable named volumes must also be declared at the bottom under volumes. That is why db_data appears in two places.

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    6. Handle Environment Variables Safely

    4 min

    In 30 seconds
    • Put secrets in env files, not inside your Dockerfile or code.
    • Wire app and database settings through Compose safely.
    • Ship an example env file so reviewers know what to create.
    Key point

    One rule

    Do not bake secrets into your image. Pass them at runtime through Compose, and commit only safe example values.

    A Dockerfile ENV value stays in the image and can be viewed later. Use it only for harmless defaults, not passwords, API keys, JWT secrets, or database URLs.

    Two env files

    You usually need two files. One real file for your laptop, and one example file for the repo.

    The real file is named .env and should be ignored by Git. The example file can be named .env.example and should be committed.

    Example

    File setup

    Your repo can show reviewers exactly what to create without leaking secrets.

    Use values that make sense locally. For a hackathon project, a simple local password is fine in .env.example if it is only for local Docker development.

    .gitignore
    .env
    node_modules
    
    .env.example
    APP_PORT=3000
    DATABASE_URL=postgres://app_user:app_password@db:5432/app_db
    POSTGRES_USER=app_user
    POSTGRES_PASSWORD=app_password
    POSTGRES_DB=app_db
    Example

    Compose wiring

    Compose can read variables from a .env file in the project directory. It can then pass them into each service container.

    Inside the app container, the database host is db because that is the Compose service name.

    services:
      app:
        build: .
        ports:
          - "127.0.0.1:${APP_PORT}:3000"
        environment:
          DATABASE_URL: ${DATABASE_URL}
        depends_on:
          - db
    
      db:
        image: postgres:16
        environment:
          POSTGRES_USER: ${POSTGRES_USER}
          POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
          POSTGRES_DB: ${POSTGRES_DB}
        volumes:
          - db_data:/var/lib/postgresql/data
    
    volumes:
      db_data:
    Your to-do

    Use it safely

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    cp .env.example .env
    docker compose up --build
    Common mistake

    Common leak

    Beginners put DATABASE_URL or API keys in the Dockerfile with ENV. That makes the value part of the image metadata.

    Another common issue is committing .env by mistake. Check git status before pushing your repo.

    git status
    Tip

    Check AI output

    If you ask ChatGPT or Gemini to write Compose config, check three things before using it.

    It should use docker compose, not old docker-compose. It should start with services:, not a top-level version:. It should not publish database ports unless you really need them from your laptop.

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    7. Make The Repo Recruiter-Ready

    4 min

    In 30 seconds
    • Turn your Docker app repo into something a reviewer can run without guessing.
    • Add clear run steps, env examples, ports, screenshots, and a small troubleshooting note.
    • Check your repo like a recruiter: clone, create env file, run one command, test the app.
    Key point

    One simple test

    A recruiter-ready repo passes the fresh laptop test. Someone should clone it, create the required environment file, run docker compose up, and see the app locally.

    Do not assume they know your college project folder, your local database name, or your secret keys.

    What reviewers look for

    Your Dockerfile and Compose file prove the app can run outside your laptop. Your README proves another human can use it.

    Think of the README as your project’s first interview answer. It should explain what the app does, how to run it, and what to check after it starts.

    Your to-do

    Repo checklist

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 6 done

    Example

    README run section

    Use a copy-paste section. Keep it boring and exact. Replace the names and ports with your project details.

    Run locally with Docker
    
    1. Clone the repo
       git clone https://github.com/your-name/your-project.git
       cd your-project
    
    2. Create the environment file
       cp .env.example .env
    
    3. Start the app and database
       docker compose up --build
    
    4. Open the app
       http://localhost:3000
    
    Expected result
    You should see the login page. If you are testing the API, open http://localhost:3000/health and expect {"status":"ok"}.
    Tip

    Use .env.example

    Commit .env.example, not .env. The example file tells reviewers what variables exist without leaking passwords, tokens, or UPI/payment test keys.

    Use safe dummy values. If a value must be created by the reviewer, write a comment beside it.

    # .env.example
    APP_PORT=3000
    DATABASE_URL=postgres://app_user:app_password@db:5432/app_db
    POSTGRES_USER=app_user
    POSTGRES_PASSWORD=app_password
    POSTGRES_DB=app_db
    JWT_SECRET=change_me_for_local_testing
    Common mistake

    Common weak README

    Beginners often write only: run npm install, start Postgres, set env, run the app. That defeats the point of this track.

    If the project uses Compose, the main path should be Docker first. Native setup can be a second section, not the main proof.

    Your to-do

    Test like a reviewer

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done

    Your to-do

    Do this now

    Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.

    0 of 5 done