# devops / containers / docker 101

Introduction to Docker

If you’ve ever faced the dreaded “It works on my machine but not on yours” problem — Docker is the hero you need. It packages your code, PHP runtime, and all dependencies into an isolated environment.

$ docker run my-app
CodeSchool Project Web
RuntimePHP 8.2
DependenciesPackaged
StatusWorks everywhere 🚀
Single
Container
Isolated
Environment
# architecture

The Engine Under the Hood

Docker operates on a client-server architecture. They communicate via REST API, Unix sockets, or a network interface.

👉 Analogy: You (the client) say “Make tea!” ☕ and the kitchen (the daemon) makes it.

interface

🖥️ Docker Client

The tool we use to interact with Docker. It runs commands like docker run or docker pull and can communicate with local or remote Daemons.

backend

⚡ Docker Daemon

The engine running in the background. It is fully responsible for building images, running containers, and managing networks and volumes.

# components

Core Puzzle Pieces

DockerfileBUILD SCRIPT
1 2 3
FROM ubuntu
RUN apt-get update && apt-get install -y nginx
CMD ["nginx", "-g", "daemon off;"]

The Container Lifecycle

  • pull

    Download a read-only Image from a Registry (like Docker Hub).

    docker pull ubuntu
  • create

    Initialize a Container, adding a temporary read-write layer on top of the image.

    Ephemeral by default
  • network

    Connect the container to a virtual network and assign it a unique IP.

    Bridged networking
  • interact

    Execute your code, open a terminal, or expose ports to the host machine.

    docker run -p 80:80
# commands

Common Docker Commands

Whether you are building infrastructure or troubleshooting an application, you will spend most of your time interacting with the Docker CLI using these image and container commands.

terminal
# Image Commands
$ docker image ls → List all downloaded images
$ docker pull <image> → Download an image from Hub
$ docker rmi <image> → Remove an image from host
$ docker history <image> → View the layers of an image
 
# Container Commands
$ docker run -d -p 80:80 nginx → Run Nginx in background
$ docker ps -a → List all active & stopped containers
$ docker exec -it <id> /bin/bash → Open terminal inside container
$ docker logs <id> → View standard output/error logs
$
# comparison

🥊 Docker vs Virtual Machine

Feature Docker (Container) Virtual Machine (VM)
Startup Time Seconds ⚡ Minutes 🕒
Resource Usage Lightweight 🪶 Heavy 💻
OS Requirement Shares Host OS Needs Full Guest OS
Performance Faster 🚀 Slower 🐢
Isolation Process-level Hardware-level
USE CASE 1

Want to run 10 microservices on a single server without overhead? → Use containers.

USE CASE 2

Want to run a Windows application natively on a Linux host server? → Use a Virtual Machine.