What is Docker?
Docker packages your application and its dependencies into a container — a lightweight, portable unit that runs consistently everywhere. Think of it as a shipping container for software.
Why Docker for Hosting?
Consistency
"It works on my machine" becomes "It works everywhere":
- Same environment in development and production
- No dependency conflicts
- Reproducible deployments
Isolation
Each container runs independently:
- One container crashing doesn't affect others
- Different PHP versions for different sites
- Security isolation between applications
Efficiency
Containers are lightweight:
- Start in seconds (vs minutes for VMs)
- Share the host OS kernel
- Use less memory and disk
Core Concepts
Images
A read-only template containing your application:
# Dockerfile
FROM php:8.2-apache
COPY ./src /var/www/html
RUN docker-php-ext-install mysqli pdo pdo_mysql
EXPOSE 80Containers
A running instance of an image:
docker run -d -p 80:80 --name my-website my-imageDocker Compose
Define multi-container applications:
# docker-compose.yml
services:
web:
image: wordpress:latest
ports:
- "80:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_PASSWORD: secret
db:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: secret
volumes:
- db-data:/var/lib/mysql
volumes:
db-data:Common Docker Commands
# Container management
docker ps # List running containers
docker ps -a # List all containers
docker start container_name # Start container
docker stop container_name # Stop container
docker logs container_name # View logs
docker exec -it container_name bash # Shell into container
# Image management
docker images # List images
docker pull nginx:latest # Download image
docker build -t myapp . # Build from Dockerfile
# Cleanup
docker system prune # Remove unused dataHosting Multiple Sites
Docker makes it easy to host multiple websites on one server:
services:
site1:
image: wordpress:latest
environment:
VIRTUAL_HOST: site1.com
site2:
image: wordpress:latest
environment:
VIRTUAL_HOST: site2.com
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:roConclusion
Docker is the future of web hosting infrastructure. Start with Docker Compose for simple multi-container setups, and you will quickly appreciate the consistency, isolation, and efficiency it provides.