Dockerizing Symfony Apps Dennis Benkert @denderello
Set out to make service orchestration simple for developers. Based in Cologne, Germany. Ten terrific folks, and hiring! http://giantswarm.io/
So, Docker ... It’s that new kid everybody talks about
Ever heard about it?
It will help you to ... ● run your environment everywhere ● try out infrastructure changes easier ● deploy new releases faster ● run PHP without installing it locally!
How is that possible?
Docker’s Building Blocks Watch out. Linux Kernel ahead!
What are Docker Containers?
Linux Containers + Union Filesystems
Remember Virtual Machines?
They use Hypervisors
Hypervisors virtualize a whole system
Virtual Machines Machine Kernel Init Hypervisor VM VM VM Kernel Kernel Kernel Init Init Init Process Process Process Process Process Process
Try to start 100 of them on your laptop … ;-)
Linux Containers are lightweight virtualization
Linux Containers ... ● run in their own Kernel namespace ● are standalone processes ● only see processes inside them ● cannot see outside processes ● share the kernel instance ● can have their own filesystem ● can be isolated using CGroups
Linux Containers Machine Kernel Init Container Container Container Process Process Process
Think of stacked layers
Every write operation opens a new layer
Union filesystem Change /etc/php5/fpm/php.ini Install PHP-FPM Basic Ubuntu RootFS
You will see a combined view of all layers
Imagine your webserver is a layer
And every project release becomes a layer on top
Run this filesystem as a single process
You have Docker Containers!
Docker Containers is “chroot on steroids.” — Jérôme Petazzoni (Docker)
Sounds hard to achieve?
Docker makes this super easy!
Four steps needed
1. Create a PHP file <?php echo "Hello from PHP";
2. Create a Dockerfile FROM php Every line ADD index.php /var/www becomes a layer EXPOSE 8080 WORKDIR /var/www ENTRYPOINT ["php", "-S", "0.0.0.0:8080"]
3. Build your Container $ docker build -t denderello/phptest .
4. Run your Container $ docker run -d -p 8080:8080 denderello/phptest $ curl 127.0.0.1:8080 Hello from PHP Binds local port to exposed port
You can run this Container everywhere!
The Dockerhub saves your Containers D push run Dev Prod Docker daemon Docker daemon Docker client Docker client
Let’s get started Symfony, get ready to become dockerized!
Imagine a simple Symfony app
A classic setup nginx / fpm Redis Symfony
Let’s break this up into processes
Seperate the processes Redis fpm nginx
Every process becomes a container
nginx and fpm need to share the source files
Incorporation of nginx and PHP-FPM fpm nginx Symfony
Let’s add a volume container
Volume containers share folders with other containers