Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vvinhas's avatar

Is there anyone using Docker with Laravel?

Hi!

As some of you may know, Docker (docker.com) is the new sensation out there when you talk about distributed applications. You can have a glance here https://www.docker.com/whatisdocker/

Some people are talking about migrate from Vagrant to Docker, but it's very soon (for me at least) to do such a thing, specially when the team behind it advise not to use it in production. Though many people are ignoring them... lol

It's a nice and polished solution that provides lots of benefits for both developers and sysadmins. Some people are already working to make a Laravel development environment using Docker, which is cool :)

The concept is not very clear to me yet, and I would love to hear if there's anyone using it already!

0 likes
9 replies
MWrathDev's avatar

First and foremost, you are quite right in saying: "it's very soon (for me at least) to do such a thing" Since it really only runs on linux. However i am aware that Microsoft are working diligently to get it working with their servers and azure platform which should provide some exciting opportunities to port linux applications to windows and vice versa.

I have looked into it, and i would definitely say it's something im going to be using consistently over any other virtualization software, including vagrant. The reasons being:

a. It uses far less system resources then vagrant if you need multiple virtual machines. For example if you're using a storage solution that is distributed (relational databases with sharding, couchbase, etc) and are developing to scale horizontally. Mimicking a server cluster with vagrant locally for development is quite tricky and taxing on system resources. However with docker you can have multiple containers that use the same kernel so you can 'spin up' 5, 10 or 15 servers with very little impact to system performance.

b. You can split your development environment into multiple pieces. Something that's bugged me for a while is how vagrant is an all-in-one type of solution. For example take homestead: http://laravel.com/docs/4.2/homestead Now nothing against this, as one that's used it almost religiously, it is a fantastic solution for developers that lets them start coding ASAP regardless of which OS they use natively.

The problem is what happens when you move from development to deployment/updating? For instance you're probably only using one form of database storage (in this case lets say it's MySQL) yet homestead ships with both postgres and redis as well, because it has to cater for people that would be using those other technologies. Lets look at it from another angle, by default it ships with NGINX, but what if you're using nodeJS as the server or some other OS (Litespeed, apache)... there is no reason for NGINX being present in that case.

As a result you can't just take your virtual machine and push the contents to a server because there would be natural redundancies. However with docker you can have, different things in different containers and then swap them out like lego blocks and only deploy what you need: - front end dev tools (NodeJS, Ruby, SASS, yeoman, bower, gulp, grunt) - database tech (couchbase, postgres, mysql, etc) - server tech (NGINX, apache, etc). - kernel

For example, lets say you're only developing an opensource simple static website. In that case you only need to spin up the 'front end dev tools' container and you can share that whole when you're done without having to mess around removing other components.

c. Every change to a container is managed like a git commit therefore for example you can sync up with your server in the cloud and any changes that are made can be pushed to the server in that form without having to reupload the whole VM image.

Finally you may be thinking this is all very well and good but what if i don't want to have to manage individual containers but i still want the modularity? Never fear, docker purchased fig a little while back: http://www.fig.sh/ A simple YAML file and command from the terminal and you can spin up multiple containers with whatever you want in them.

Docker is definitely worth a look (particularly if you run linux natively), but is still in it's infancy for other platforms.

11 likes
stresler's avatar

We are, but we are still pre-launch. It took a while for me to wrap my mind around the best way to set it up and I'm not saying I have it right yet, but what I've landed on is a single image that I launch two times with different commands. One of them starts nginx and serves static non-dynamic assets, the other starts php5-fpm and handles php execution. We have another haproxy container that sits in front of nginx, and our app is api driven so there is no DB in this scenario.

I was inspired to do it this way through this article https://grey-boundary.io/scaling-via-php-fpm-clustering/ which is caustic in tone, but makes a good point about why scale nginx when it isn'tthe bottleneck. With this set up I can just add more php5-fpm containers when I need them.

Let me know if I can answer any questions. Again, I stress, we haven't put this into production yet.

2 likes
jimmy.puckett's avatar

I'd like to add a "d" to @MWrathDev response...

d. With several of the hosting companies starting to support running containers, it is going to allow you to run the EXACT same server/container on your local development box as you have in the real world. This is a huge pro of docker, and we are doing it now.

We are not using docker in production--yet, but we are building our docker containers with the exact same chief recipes using packer when it builds our AMI's or VMDK's, so they are very near the same. We are just using the containers for our "local" environment, and plan to test things out there for the next several months. Then we are going to start moving up the line development->qanda->production/sandbox.

We are actually working on a homestead port that will replace the single box with containers, so we will try to OS that in the next month or so.

MWrathDev's avatar

@jimmy.puckett

Indeed i wholeheartedly agree with this point.

Once docker is set up properly it makes it very easy to mimic environments with a greater degree of accuracy regardless if they're natively or virtually configured in your server environment and because of the GIT-like management concerning changes to containers it becomes simple to make configuration adjustments and push them out to your server or vice versa.

As i said though it's not quite there with windows yet, im hoping for a release coinciding with windows10 so i can build a streamlined install and deploy to most of my dev machines at once. Mac users watch out :P windows is about to join linux in becoming the top dogs of the food chain for devs :)

2 likes
harshjv's avatar

You can also make aliases of frequently used commands, like;

alias phpcmd='docker-composer run --rm phpnginx php'

Then use it,

phpcmd composer.phar install
1 like

Please or to participate in this conversation.