๐ณ Get Started with Docker: Step-by-Step Guide to Build & Modify a Web App
✅ What You’ll Do:
-
Clone a ready-made app project
-
Start the app using Docker
-
Make simple changes to backend, frontend, and design
-
See updates live in your browser
๐ง Step 1: Install Docker Desktop
Make sure you’ve installed Docker Desktop on your system.
๐ Download here if not done yet
๐ Step 2: Download the Project
Open your terminal and clone the example project from GitHub:
Move into the project folder:
๐ Step 3: Start the Application
Start the application using Docker Compose Watch (which auto-reloads on changes):
๐ This command:
-
Pulls necessary Docker images
-
Starts containers (backend, frontend, DB, etc.)
-
Sets up the full environment for development
Wait until setup completes (a few seconds to a couple of minutes).
๐ Step 4: Open the App in Browser
Go to:
✅ You’ll see a simple To-Do app.
๐ What's Inside the Docker Environment?
You’re now running 5 services inside Docker containers:
| Service | Purpose |
|---|---|
| ๐ฅ React frontend | Built with Vite, handles user interface |
| ๐ Node backend | Handles API (Add/Delete/Get to-do items) |
| ๐ MySQL DB | Stores your to-do list |
| ๐ง๐ป phpMyAdmin | Manage DB at http://db.localhost |
| ๐ Traefik proxy | Routes requests to correct services (port 80) |
๐ You didn’t need to install Node, MySQL, or phpMyAdmin manually—Docker did it for you.
✏️ Step 5: Make Backend Change (Greeting Message)
-
Open this file in a text editor:
-
Replace its content with:
-
Save the file.
-
Refresh your browser and you’ll see a random greeting message each time.
✏️ Step 6: Change Placeholder Text (Frontend)
-
Open this file:
-
Find the following code and update the
placeholder:
-
Save the file and check your browser—it will update automatically!
๐จ Step 7: Change the Background Color
-
Open this file:
-
Modify the
background-colorlike this:
-
Save the file and refresh your browser to see the change instantly.
✅ Recap – What You Achieved
✔️ Started a complete development app with Docker (no need to install Node, MySQL, etc.)
✔️ Edited backend logic and saw results instantly
✔️ Updated frontend text and style, live in your browser
✔️ Experienced the power of container-based development
docker compose file for above repo is
services:
proxy:
image: traefik:v3.4
command: --providers.docker
ports:
- 80:80
volumes:
- /var/run/docker.sock:/var/run/docker.sock
backend:
build:
context: ./
target: backend-dev
environment:
MYSQL_HOST: mysql
MYSQL_USER: root
MYSQL_PASSWORD: secret
MYSQL_DB: todos
depends_on:
mysql:
condition: service_healthy
develop:
watch:
- path: ./backend/src
action: sync
target: /usr/local/app/src
- path: ./backend/package.json
action: rebuild
labels:
traefik.http.routers.backend.rule: Host(`localhost`) && PathPrefix(`/api`)
traefik.http.services.backend.loadbalancer.server.port: 3000
client:
build:
context: ./
target: client-dev
develop:
watch:
- path: ./client/src
action: sync
target: /usr/local/app/src
- path: ./client/package.json
action: rebuild
labels:
traefik.http.routers.client.rule: Host(`localhost`)
traefik.http.services.client.loadbalancer.server.port: 5173
mysql:
image: mysql:9.3
volumes:
- todo-mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: todos
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 5s
timeout: 5s
retries: 5
phpmyadmin:
image: phpmyadmin
environment:
PMA_HOST: mysql
PMA_USER: root
PMA_PASSWORD: secret
labels:
traefik.http.routers.phpmyadmin.rule: Host(`db.localhost`)
traefik.http.services.phpmyadmin.loadbalancer.server.port: 80
volumes:
todo-mysql-data:
๐งฑ Step-by-Step Breakdown of Each Service
๐ฆ 1. proxy — Reverse Proxy using Traefik
-
Acts like a traffic cop: decides whether a request should go to the backend, frontend, or phpMyAdmin.
-
Exposes port 80 to the outside world.
-
Uses Docker socket to watch containers and apply rules using labels (you’ll see labels in other services).
๐ป 2. backend — Node.js API
-
Built from the Dockerfile in the root (
context: ./), using the stagebackend-dev. -
Environment variables are used to connect to the MySQL database.
-
Uses
develop.watchto auto-sync code changes (hot reload). -
Labels tell Traefik to route
localhost/apitraffic here.
๐ 3. client — React Frontend
-
Also built from the root directory but targets
client-devstage. -
Hot reloads code using the
develop.watch. -
Routes all traffic to
localhost(except/apianddb.localhost) to this service on port 5173.
๐ข️ 4. mysql — MySQL Database
-
Uses the MySQL official image.
-
Stores data in a volume so it doesn’t get lost when containers stop.
-
Runs a health check to make sure it's ready before backend connects.
๐งฐ 5. phpmyadmin — DB Admin Interface
-
Web UI for MySQL (handy for debugging).
-
Access it via
http://db.localhost(routed by Traefik). -
Connects to the
mysqlservice with default login credentials.
๐️ Volume: todo-mysql-data
This volume is used to store MySQL data, so that it's not lost when the container stops.
| Service | URL |
|---|---|
| React Frontend | http://localhost |
| Backend API | http://localhost/api |
| phpMyAdmin | http://db.localhost |
๐น Top-Level Key: services
Defines all the individual containers (services) to be run.
๐ธ proxy service:
-
Use the Traefik v3.4 image (a reverse proxy/load balancer).
-
Tells Traefik to watch Docker containers for dynamic routing configuration.
-
Maps port 80 of the host to port 80 of the container, exposing HTTP traffic.
-
Mounts the Docker socket so Traefik can detect running containers and route traffic accordingly.
๐ธ backend service:
-
Builds the image from the current directory.
-
Uses the
backend-devstage from the Dockerfile.
-
Sets environment variables (used to connect to the MySQL database container).
-
Waits for the MySQL service to be healthy before starting this container.
-
Watches files during development:
-
Syncs changes in
srcto container. -
Rebuilds container if
package.jsonchanges.
-
-
Tells Traefik to route traffic to
/apipath onlocalhostto this service. -
Port 3000 is exposed inside the container.
๐ธ client service:
-
Similar to backend, builds client image using Dockerfile with target
client-dev.
-
Same as backend — watches files for sync or rebuild during development.
-
Traefik routes all
localhosttraffic (not/api) to this service on port 5173.
๐ธ mysql service:
-
Uses official MySQL version 9.3 image.
-
Mounts persistent storage volume to keep database data even if container is destroyed.
-
Creates a MySQL DB named
todosand sets the root password.
-
Docker checks if MySQL is alive and responsive every 5 seconds. It will retry 5 times.
๐ธ phpmyadmin service:
-
Uses official phpMyAdmin image for DB GUI.
-
Connects phpMyAdmin to the MySQL container using provided credentials.
-
Traefik will expose phpMyAdmin on
http://db.localhost.
๐น volumes (bottom of file):
-
Defines a named volume to store MySQL data persistently.
๐ณ Build & Push Your First Docker Image to Docker Hub — Step-by-Step Guide
✅ Prerequisites
-
Install Docker Desktop
๐ Download it here -
Create a Docker Hub account
๐ Sign up here -
Login to Docker Hub from terminal
Run:Enter your Docker Hub username and password when prompted.
๐ ️ Step 1: Create a Project Directory
-
Create a folder for your project:
-
Create a simple app file, e.g.,
app.py(Python example): -
Create a Dockerfile in the same folder:
๐งฑ Step 2: Build the Docker Image
Run the following command to build your image:
๐ธ Replace
your-dockerhub-usernamewith your actual Docker Hub username.
Example:
✅ If successful, you’ll see Successfully tagged obul123/my-docker-app:latest at the end.
๐งช Step 3: Run the Docker Image (Optional Test)
Make sure your image works by running:
Expected output:
๐ Step 4: Push Image to Docker Hub
Now, push your image to your Docker Hub repository:
Example:
✅ If successful, you’ll see upload progress and then pushed confirmation.
๐ Step 5: Verify on Docker Hub
-
Go to https://hub.docker.com/
-
Log in to your account
-
You’ll see the newly pushed image under Repositories
๐ Recap
| Step | Action |
|---|---|
| Install Docker | Install Docker Desktop |
| Login | Use docker login to authenticate with Docker Hub |
| Create App | Write a simple Python app and a Dockerfile |
| Build Image | Use docker build -t username/image-name . to build the image |
| Test Image | Run locally with docker run |
| Push to Docker | Push the image using docker push |
| Verify | Check your image on Docker Hub |
Comments
Post a Comment