SlideShare a Scribd company logo
1 of 34
Download to read offline
Hi there! I'm Erika
● DevOps Technical Writer
● Linux and open source enthusiast
● SysAdmin and PHP dev background
● Twitter: @erikaheidi
● Part 1: PHP development environments in the wild,
how Docker Compose fits in
● Part 2: Building a multi-container environment for
Laravel with Docker Compose
● Part 3: Demo
Talk Goals
Setting Expectations
Introduction:
Development Environments,
PHP, and Docker Compose
Part 1
PHP Development
Environments
A Delightful (and Personal) Timeline
● Part 1: PHP development environments in the wild,
how Docker Compose fits in
● Part 2: Building a multi-container environment for
Laravel with Docker Compose
● Part 3: Demo
Talk Goals
Setting Expectations
2000's
The Age of Wamp/Xampp and FTP
~2010
Local env and the rise of Git
● Pros:
○ Share, dispose and replicate full envs
○ Easy to Understand
● Cons:
○ Big Footprint
○ Depends on Automation Tools
~2012
Vagrant / VMs
● Pros:
○ Small footprint, fast and lightweight
○ Eliminates need for heavy automation
● Cons:
○ Not as intuitive as VMs
○ Defining and managing (micro) services
~2014
Docker / Containers
Docker Compose
A Hero to the Rescue
What is Compose
Docker Compose is a tool that allows you to run
multi-container application environments
based on definitions set in a YAML file.
It uses service definitions to build fully
customizable environments with multiple
containers that can share networks and data
volumes.
● Easy to set up and
manage
● Multiple composed
envs on a single host
● Preserves volume data
● Variables to allow
customization
Example
Nginx Service
docker-compose.yml
version: '3.7'
services:
web:
image: nginx
ports:
- "8000:80"
This simple
docker-compose.yml
file creates a service
container based on an
"nginx" image,
redirecting all requests
on local port 8000 to
port 80 in the container.
Up and
Running
docker-compose up
● Controlling the Environment
○ up | down | stop | start
● Monitoring & Troubleshooting
○ ps | logs | top | kill
● Executing Commands on containers
○ exec service_name command
Using Docker Compose
docker-compose [ command ]
Case Study
Travellist: a Laravel demo
application
Part 2
Travellist
A demo Laravel app
Environment Needs
Requirements for running PHP
Web Server: Nginx
We'll use Nginx to serve
the application in our
development
environment.
Database: MySQL
The application uses a
MySQL database to store
places and mark them as
"visited" or "to go".
PHP-FPM
PHP-FPM is required to
parse the PHP content
and return the results to
Nginx.
Application Needs
Laravel Requirements (DEV)
PHP Extensions
Laravel requires a few
different PHP extensions
that should be installed
on the application
container.
Artisan Commands
We need the ability to run
Artisan and Composer
commands from the host
machine.
Composer PHP
In order to install and
update Laravel's
dependencies, we'll need
Composer installed on the
application container.
Containers & Images
● Nginx
○ pre-built image
● MySQL
○ pre-built image
● App (PHP-FPM)
○ Image based on custom Dockerfile
Shared Volumes & Networks
Volumes
● Application files
○ host app, nginx
● Nginx configuration file
○ host nginx
● MySQL database dump
○ host mysql
Networks
● host app, nginx, mysql
Setting Up a
docker-compose.yml
Configuring service containers, volumes and
networks
App+PHPdocker-compose.yml
app:
build:
context: ./
dockerfile: Dockerfile
image: travellist
container_name: travellist-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- travellist
This service will be
responsible for parsing
all PHP requests and
command-line calls
made with Composer
and Artisan. It will build
a new image based on
the provided Dockerfile.
Nginxdocker-compose.yml
nginx:
image: nginx:1.17-alpine
container_name: travellist-nginx
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d
networks:
- travellist
This service will be
responsible for serving
the application via
Nginx. A port
redirection will allow us
to access port 80 inside
the container through
port 8000 in the host.
DBdocker-compose.yml
db:
image: mysql:5.7
container_name: travellist-db
restart: unless-stopped
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
...
This service will run a
MySQL database to
store the application's
data. It will extract
values from the .env
Laravel file to create a
new DB and user.
DB (cont)docker-compose.yml
...
volumes:
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
networks:
- travellist
The shared volume
contains a .sql file that
will be automatically
imported (a feature
provided by this image).
App Dockerfile
Building a custom image based on php-fpm to
meet application needs
Dockerfile
App+PHP
container
Dockerfile
FROM php:7.4-fpm
ARG uid=1000
ARG user=sammy
RUN apt-get update && apt-get install -y 
git 
curl 
libpng-dev 
libonig-dev 
libxml2-dev 
zip 
unzip
...
This Dockerfile will build
a new image based on
the php:7.4-fpm
official PHP image.
We start by installing
some required system
packages.
Dockerfile
App+PHP
container
Dockerfile
…
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && 
chown -R $user:$user /home/$user
...
Variables are used to
create a new user and
grant them the same
privileges as your
current system user on
the host, so that you
don't run into
permission issues with
synced files.
Dockerfile
App+PHP
container
Dockerfile
...
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /var/www
USER $user
We then install
Composer, set the work
dir and change to the
new user, so that when
we run commands via
docker-compose exec,
they are executed as
the new system user.
Directory
Tree
TERMINAL
application/
├── docker-compose
│ ├── mysql
│ │ └── init_db.sql
│ └── nginx
| └── travellist.conf
├── Dockerfile
└── docker-compose.yml
Here's an overview of
what our Docker
Compose setup looks
like, excluding the
application files.
Demo Time!
Part 3
Questions?
@erikaheidi
THANK YOU!
@erikaheidi

More Related Content

More from DigitalOcean

Kubernetes for Beginners
Kubernetes for BeginnersKubernetes for Beginners
Kubernetes for Beginners
DigitalOcean
 
Secrets to Building & Scaling SRE Teams
Secrets to Building & Scaling SRE TeamsSecrets to Building & Scaling SRE Teams
Secrets to Building & Scaling SRE Teams
DigitalOcean
 

More from DigitalOcean (16)

Build, Deploy, and Scale Your First Web App Using DigitalOcean App Platform
Build, Deploy, and Scale Your First Web App Using DigitalOcean App PlatformBuild, Deploy, and Scale Your First Web App Using DigitalOcean App Platform
Build, Deploy, and Scale Your First Web App Using DigitalOcean App Platform
 
Effective Kubernetes Onboarding
Effective Kubernetes OnboardingEffective Kubernetes Onboarding
Effective Kubernetes Onboarding
 
Creating Inclusive Learning Experiences
Creating Inclusive Learning ExperiencesCreating Inclusive Learning Experiences
Creating Inclusive Learning Experiences
 
Kubernetes for Beginners
Kubernetes for BeginnersKubernetes for Beginners
Kubernetes for Beginners
 
Command-line Your Way to PaaS Productivity With DigitalOcean App Platform
Command-line Your Way to PaaS Productivity With DigitalOcean App PlatformCommand-line Your Way to PaaS Productivity With DigitalOcean App Platform
Command-line Your Way to PaaS Productivity With DigitalOcean App Platform
 
Escape the Walls of PaaS: Unlock the Power & Flexibility of DigitalOcean App ...
Escape the Walls of PaaS: Unlock the Power & Flexibility of DigitalOcean App ...Escape the Walls of PaaS: Unlock the Power & Flexibility of DigitalOcean App ...
Escape the Walls of PaaS: Unlock the Power & Flexibility of DigitalOcean App ...
 
Kubernetes: Beyond Baby Steps
Kubernetes: Beyond Baby StepsKubernetes: Beyond Baby Steps
Kubernetes: Beyond Baby Steps
 
How to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsHow to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking Needs
 
Combining Cloud Native & PaaS: Building a Fully Managed Application Platform ...
Combining Cloud Native & PaaS: Building a Fully Managed Application Platform ...Combining Cloud Native & PaaS: Building a Fully Managed Application Platform ...
Combining Cloud Native & PaaS: Building a Fully Managed Application Platform ...
 
Secrets to Building & Scaling SRE Teams
Secrets to Building & Scaling SRE TeamsSecrets to Building & Scaling SRE Teams
Secrets to Building & Scaling SRE Teams
 
Deploying to DigitalOcean With GitHub Actions
Deploying to DigitalOcean With GitHub ActionsDeploying to DigitalOcean With GitHub Actions
Deploying to DigitalOcean With GitHub Actions
 
Building an Observability Platform in 389 Difficult Steps
Building an Observability Platform in 389 Difficult StepsBuilding an Observability Platform in 389 Difficult Steps
Building an Observability Platform in 389 Difficult Steps
 
Doing This Cloud Thing Right – a Lap Around DigitalOcean Products and a Roadm...
Doing This Cloud Thing Right – a Lap Around DigitalOcean Products and a Roadm...Doing This Cloud Thing Right – a Lap Around DigitalOcean Products and a Roadm...
Doing This Cloud Thing Right – a Lap Around DigitalOcean Products and a Roadm...
 
Developer Burnout: Yes, You Can Improve Your Team's Wellness
Developer Burnout: Yes, You Can Improve Your Team's WellnessDeveloper Burnout: Yes, You Can Improve Your Team's Wellness
Developer Burnout: Yes, You Can Improve Your Team's Wellness
 
Why Should You Care About Your Customer's Journey?
Why Should You Care About Your Customer's Journey?Why Should You Care About Your Customer's Journey?
Why Should You Care About Your Customer's Journey?
 
Build Apps Faster With DigitalOcean App Platform
Build Apps Faster With DigitalOcean App PlatformBuild Apps Faster With DigitalOcean App Platform
Build Apps Faster With DigitalOcean App Platform
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

How to Create PHP Developer Environments With Docker Compose