The Dev Log › Technology
Docker for Web Devs: The 20% You Actually Need
By Jezer Niel Blanca, Full Stack Developer ·
·
3 min read
Skip the container theory. Here is the small slice of Docker that covers almost everything a web developer does day to day.
Docker has a reputation for being complicated, and parts of it are. But as a web developer, I use a surprisingly small slice of it day to day. If you learn this 20%, you'll be comfortable with most projects that ship a Dockerfile or a compose.yaml.
The Only Three Concepts You Need First
- Image: a read-only template, like a class. Built from a
Dockerfile.
- Container: a running instance of an image, like an object.
- Volume: persistent storage that survives when containers are removed.
Everything else builds on these three.
Running Things
docker run --rm -it -p 8080:80 nginx:alpine
docker ps
docker logs -f <container>
docker exec -it <container> sh
docker stop <container>
The --rm flag removes the container when it stops, which keeps your machine tidy. -p host:container publishes a port so you can visit localhost:8080.
A Practical Dockerfile
Here's a lean image for a PHP app. The key idea is layer caching: copy dependency files first, install, then copy the rest of the code.
FROM php:8.3-fpm-alpine
RUN docker-php-ext-install pdo_mysql opcache
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
WORKDIR /var/www/html
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-scripts --prefer-dist
COPY . .
RUN composer dump-autoload --optimize
CMD ["php-fpm"]
Because the dependency install happens before COPY . ., changing your app code doesn't reinstall every package on the next build.
Order your Dockerfile from least frequently changed to most frequently changed. That single habit makes builds dramatically faster.
Don't Forget .dockerignore
Without it, you'll send node_modules, vendor, and .git to the build context:
.git
node_modules
vendor
.env
storage/logs
Keeping .env out of images also keeps secrets out of your registry.
Compose Is Where the Magic Happens
Real apps need more than one service. Compose describes them together:
services:
app:
build: .
volumes:
- .:/var/www/html
depends_on:
- mysql
mysql:
image: mysql:8.4
environment:
MYSQL_DATABASE: app
MYSQL_ROOT_PASSWORD: secret
ports:
- "3306:3306"
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data:
Services can reach each other by name, so your app connects to the database with DB_HOST=mysql, not 127.0.0.1.
Everyday Compose Commands
docker compose up -d
docker compose ps
docker compose logs -f app
docker compose exec app php artisan migrate
docker compose down
Use docker compose down -v only when you really want to delete volumes, because that wipes your database data.
Laravel Developers Get a Head Start
If you work with Laravel, Sail gives you a ready-made Compose setup:
composer require laravel/sail --dev
php artisan sail:install
./vendor/bin/sail up -d
./vendor/bin/sail artisan migrate
It's a great way to learn Compose by reading a well-structured real example.
Cleaning Up Disk Space
Docker quietly accumulates images and build cache. Check and clean periodically:
docker system df
docker image prune
docker builder prune
What You Can Safely Ignore for Now
- Writing your own orchestration or learning Kubernetes
- Custom network drivers
- Advanced multi-platform build setups
- Docker Swarm
These matter at scale, but they're not what makes you productive on a Tuesday afternoon.
Why It's Worth It
The payoff is consistency. The same database version, PHP extensions, and services run on every developer's machine and in CI. "It works on my machine" becomes a much rarer sentence.
Want help containerizing an existing app or setting up a smooth local environment for your team? Let's talk.
Tags: Docker, DevOps, Containers, Tooling