Rishav Kumar
Uncategorized

Docker Complete Guide: Installation on Windows & Mac + React Project Setup

6 min read

πŸ“Œ 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 TermReal World Example
ImageRecipe
ContainerCooked food
DockerfileRecipe steps
Docker HubRecipe 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

  1. Download Docker Desktop
    https://www.docker.com/products/docker-desktop/
  2. Run installer
  3. Enable WSL 2
  4. Restart system
  5. 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

InstructionDescription
FROMBase image
WORKDIRApp directory
COPYCopy files
RUNRun command
EXPOSEOpen port
CMDStart 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.

Back to Insights