Docker Complete Guide: Installation on Windows & Mac + React Project Setup
π What is Docker?
Docker is a tool that allows you to run applications inside containers.
A container is a lightweight, isolated environment that contains:
- Your application
- All required dependencies
- Runtime (Node.js, etc.)
This ensures the application runs the same way on every computer.
Docker solves the common problem:
βIt works on my machine, but not on yours.β
π§ Simple Analogy
| Docker Term | Real World Example |
|---|---|
| Image | Recipe |
| Container | Cooked food |
| Dockerfile | Recipe steps |
| Docker Hub | Recipe website |
π₯οΈ What Gets Installed with Docker
When you install Docker Desktop, it installs:
1οΈβ£ Docker Engine
- Core service that runs containers
2οΈβ£ Docker CLI
- Command-line tool (
docker run,docker build)
3οΈβ£ Docker Desktop
- GUI to manage containers and images
4οΈβ£ Virtualization Layer
- Windows β WSL 2
- Mac β Linux Virtual Machine
β οΈ Docker containers always run on Linux.
πͺ Installing Docker on Windows
Requirements
- Windows 10/11 (64-bit)
- Virtualization enabled
- Administrator access
Steps
- Download Docker Desktop
https://www.docker.com/products/docker-desktop/ - Run installer
- Enable WSL 2
- Restart system
- Open Docker Desktop
Verify Installation
docker --version docker run hello-world ### π Installing Docker on macOS Requirements macOS 10.15+ Intel or Apple Silicon #### Steps 1. Download Docker Desktop for Mac 2. Drag Docker to Applications 3. Open Docker Desktop 4. Allow permissions ### Verify Installation ```bash docker --version docker run hello-world
# π¦ Core Docker Concepts ## πΉ Docker Image - Blueprint for containers - Read-only ## πΉ Docker Container - Running instance of an image ## πΉ Dockerfile - Instructions to create an image ## πΉ Docker Hub - Online image repository --- # βοΈ Create a React Application ```bash npx create-react-app my-react-app cd my-react-app
Folder structure:
my-react-app/ βββ src/ βββ public/ βββ package.json βββ Dockerfile
π Dockerfile for React App
Create a file named Dockerfile in the project root:
FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm install COPY . . EXPOSE 3000 CMD ["npm", "start"]
π Dockerfile Explanation
| Instruction | Description |
|---|---|
| FROM | Base image |
| WORKDIR | App directory |
| COPY | Copy files |
| RUN | Run command |
| EXPOSE | Open port |
| CMD | Start app |
π« Create .dockerignore
Create a file named .dockerignore and add:
node_modules build .git
This prevents unnecessary files from being added to the image.
ποΈ Build Docker Image
docker build -t react-docker-app .
βΆοΈ Run Docker Container
docker run -p 3000:3000 react-docker-app
Open browser: π http://localhost:3000
π Enable Live Reload (Optional)
docker run -p 3000:3000 \ -v $(pwd):/app \ -v /app/node_modules \ react-docker-app
π§° Common Docker Commands
docker images docker ps docker ps -a docker stop <container_id> docker rm <container_id> docker rmi <image_id>
β Common Beginner Mistakes
- Forgetting
.dockerignore - Not mapping ports
- Installing Node locally and inside Docker
- Rebuilding image unnecessarily
π§ When Should You Use Docker?
β Team projects β CI/CD pipelines β Same environment everywhere β Small learning projects (optional)
π Conclusion
Docker helps you:
- Avoid environment issues
- Run applications consistently
- Prepare for production
Learn Docker step by step. Do not jump into Kubernetes immediately.