What is Docker? (Simple Definition)
Docker is a tool that allows you to package your application with everything it needs to run — into a single unit called a container. Think of it like putting your app into a sealed box with: The code The server The OS-level dependencies Config files So it runs the same everywhere — your laptop, a testing server, or on production (like AWS, Vercel, etc.).
Vivek Rastogi
7/31/20252 min read
Why Do Developers Use Docker?
Without Docker: "It works on my machine, not on the server!”
With Docker: "The environment is the same everywhere — no more config issues or “missing dependency” errors."
Real-Life Analogy
Imagine you’re a chef preparing a dish in your kitchen. You want to ship your recipe to another chef far away.
Without Docker:
You give them ingredients and instructions. But their kitchen may not have the same tools, so the dish may fail.
With Docker:
You ship the whole ready-made kitchen with ingredients, tools, and instructions. They just plug it in and cook.
What is a Docker Container?
A container is a lightweight, standalone, and executable package that includes:
App code
Libraries
Runtime (e.g., Node, PHP)
Configuration
It runs isolated from the host machine — so it doesn’t mess with your system settings.
What is a Docker Image?
A Docker Image is a blueprint.
You create an image with a Dockerfile, and Docker uses that image to launch containers.
Think of it as:
Image = Class (Definition)
Container = Object (Instance)


🧾 Example:
Run a Laravel application in Docker with MySQL as the database — all containerized


Step 1: Create Dockerfile (Laravel App)
This file tells Docker how to build your Laravel app image.
# Dockerfile
FROM php:8.2-fpm
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim unzip git curl \
libonig-dev \
libxml2-dev \
libzip-dev
# Install PHP extensions
RUN docker-php-ext-install pdo pdo_mysql mbstring exif pcntl bcmath gd zip
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /var/www
COPY . .
RUN composer install
CMD ["php-fpm"]
EXPOSE 9000
Step 2: Create docker-compose.yml
This file defines and runs multi-container Docker apps — here: Laravel (PHP), MySQL, Nginx.
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
image: laravel-app
container_name: laravel-app
restart: unless-stopped
working_dir: /var/www
volumes:
- ./:/var/www
networks:
- laravel
db:
image: mysql:8.0
container_name: mysql-db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: laravel
MYSQL_USER: user
MYSQL_PASSWORD: password
ports:
- "3306:3306"
volumes:
- db_data:/var/lib/mysql
networks:
- laravel
nginx:
image: nginx:alpine
container_name: nginx-server
restart: unless-stopped
ports:
- "8000:80"
volumes:
- ./:/var/www
- ./nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- app
networks:
- laravel
volumes:
db_data:
networks:
laravel:
driver: bridge
Step 3: Create nginx.conf
# nginx.conf
server {
listen 80;
index index.php index.html;
server_name localhost;
root /var/www/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ /\.ht {
deny all;
}
}
Step 4: Update Laravel .env File
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=user
DB_PASSWORD=password
Step 5: Start Docker
In your project folder, run: docker-compose up -d
Then run the Laravel setup:
docker exec -it laravel-app php artisan migrate
docker exec -it laravel-app php artisan key:generate
Visit the app in browser:
👉 http://localhost:8000
✅ What You Just Did
You now have:
A Laravel container running PHP + Composer
A MySQL container with persistent storage
Nginx as a web server routing traffic to Laravel
Isolated, portable setup that works across any machine
🧩 Why This is Awesome
No need to install PHP/MySQL on your system
Same environment in dev, staging, or production
Easily sharable and deployable (on AWS, EC2, etc.)