Docker Practice Docker vs No Docker

DevOps — Practical Steps (WSL + Git + Docker)

Step-by-step commands and explanations. Follow in order. Designed for Windows users with WSL2.

Prerequisite: Windows with WSL2 enabled (Ubuntu recommended)
Goal: From Linux terminal → create a Dockerized static page and run it locally
  1. Open your WSL (Ubuntu) terminal
    Open Ubuntu from the Start menu. You should see a prompt like youruser@DESKTOP:~$.
  2. Update packages
    sudo apt update && sudo apt upgrade -y
    Refresh package lists and upgrade installed packages. Do this before installing new tools.
  3. Install helpful utilities
    sudo apt install curl wget vim net-tools unzip -y
    Installs tools you will frequently use (downloaders, editor, networking helpers, unzip).
  4. Install Git (if not already)
    sudo apt install git -y
    
    # Configure identity
    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    
    # Verify
    git --version
    git config --list
    Git is the source-control foundation used to trigger CI/CD and collaborate. Replace name/email with yours.
  5. Create a project folder
    mkdir -p ~/myapp && cd ~/myapp
    All demo files will live inside ~/myapp. Use pwd to confirm your location.
  6. Create the HTML file (avoid bash history expansion)
    # Option A (recommended)
    echo '<h1>Hello from Docker!</h1>' > index.html
    
    # Option B (escape the ! if needed)
    echo "<h1>Hello from Docker\!</h1>" > index.html
    
    # Verify
    cat index.html
    Bash treats ! as history; use single quotes or escape it. Check the file with cat.
  7. Create the Dockerfile
    # Create and open Dockerfile
    nano Dockerfile
    
    # Paste this inside Dockerfile
    FROM nginx:alpine
    COPY index.html /usr/share/nginx/html/index.html
    EXPOSE 80
    
    # Save and exit (Ctrl+O, Enter, Ctrl+X)
    This Dockerfile uses a lightweight nginx image and places your static index.html into the server's web root.
  8. Fix Docker permissions (if you see socket permission errors)
    # Add your Linux user to the docker group
    sudo usermod -aG docker $USER
    
    # Apply group change without logout (temporary)
    newgrp docker
    
    # Or run with sudo (temporary)
    sudo docker build -t myapp .
    Adding yourself to the docker group allows running Docker without sudo. You may need to log out and back in.
  9. Build the Docker image
    docker build -t myapp .
    This pulls the base image (nginx:alpine) from Docker Hub and builds an image named myapp. If pull fails, continue to networking troubleshooting below.
  10. Run the container
    docker run -d -p 8080:80 myapp
    
    # Confirm running containers
    docker ps
    Maps host port 8080 to container port 80 and runs the container in the background. Use docker ps to see it.
  11. Open the app in your browser
    # On the Windows host
    # Open: http://localhost:8080
    If Docker Desktop uses WSL2 backend, access the container via localhost on Windows. You should see your "Hello from Docker!" page.
  12. Network / Image pull troubleshooting
    If Docker fails to pull images (DNS or no route), check network inside WSL or VM. Run:
    ping -c 4 google.com
    curl -v https://registry-1.docker.io/v2/
    If name resolution fails, verify your VM/WSL network mode (NAT recommended) or fix DNS (/etc/resolv.conf) temporarily by adding a public resolver like 1.1.1.1.
    For VMware VMs: set network adapter to NAT. For WSL: ensure Windows has internet and WSL can reach it. Restart Docker and try again.
  13. Optional: Push your image to Docker Hub
    # Tag image
    docker tag myapp yourhubuser/myapp:latest
    # Login
    docker login
    # Push
    docker push yourhubuser/myapp:latest
    Pushing to Docker Hub allows deploying the same image from CI pipelines or Kubernetes clusters.
  14. Next steps for DevOps
    1. Automate build with GitHub Actions or Jenkins triggered on git push.
    2. Container registry: use Docker Hub, GitHub Container Registry, or AWS ECR.
    3. Deploy to Kubernetes (minikube or Docker Desktop k8s) using manifests.
    4. Learn Terraform/Ansible to provision infra as code.
    5. Add monitoring: Prometheus + Grafana + centralized logging (ELK).