Laravel Development with Docker

One of the challenges every development team faces is managing a consistent local environment to work in. Tools like Vagrant have made this easier in the past but working with heavy VM’s can be time consuming and quite taxing on your computer’s resources. Laravel is a great PHP framework for building web applications and provides some officially supported solutions for this as well with Homestead and Valet. But what if you want tighter control over your local environment without the burden of managing VMs?

That’s where Docker comes in! Docker provides a way to build and run lightweight containers for any service you would need. Need to make a change to PHP-FPM configuration? Want to change which version of PHP you’re using?

With Docker you can destroy your entire environment, reconfigure, and spin it back up in a matter of seconds.

tldr; If you just want to see the code check for a base Laravel install setup with Docker. See the gif at the end for an example of how quickly you can destroy and rebuild the entire environment :)

Because Laravel integrates with many other technologies (MySQL, Redis, Memcached, etc.) it can be a little tricky to get configured just right when you start out. My goal with this post is to provide a high level (but usable) understanding of running apps with Docker.

Laravel setup

For the purposes of this post any Laravel or Lumen installation will work. If you already have an app, you can follow along using that. Here we’ll use theLaravel Installer to setup a quick new app.

$ laravel new dockerApp Application ready! Build something amazing.

We can verify its setup correctly by using the quick built-in server

$ cd dockerApp $ php artisan serve

Docker setup

Docker now runs natively for Mac, Windows, and Linux. Click on the platform of your choice to install Docker on your machine. This should install Docker, as well as Docker Compose which we will use.

After installing you should be able run commands with docker

$ docker --version Docker version 1.12.0, build 8eab29e $ docker-compose --version docker-compose version 1.8.0, build f3628c7 $ docker ps CONTAINER ID IMAGE COMMAND ...

If docker ps returns an error, make sure that the Docker daemon is running. You may need to open Docker and start it manually.

Local environment with Docker

Originally published at

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.