Vagrant + Docker

Standardizing a development environment with Docker is challenging for a variety of reasons, the most common being that Docker simply is not the best of friends with Windows; particularly versions before Windows 10.

Regardless, when you’re running a modern development team with engineers and designers who have varying preferences of workstation, your environment needs to support them all.

In the past, we used Vagrant + Virtualbox + Ansible to build a virtual machine and we went from there. These days using Docker we can support an even deeper level of abstraction where you can run the environment natively, or in scenarios like Windows or on remote servers for demo purposes or what-not, we’ll run on a virtual machine or remote server.

All that to say we can now run docker+vagrant together to support this type of workflow. This way if you want to load up an environment on something where Docker isn’t supported well, you can run it through a virtual-machine with Vagrant, and otherwise just natively run docker-compose and be on your way.

First, our docker-compose:

Now, our Vagrantfile:

Third, we’ll want to abstract our configuration values to .env

Finally, application configuration

There will be things you’ll want to configure specific to your application and web-server to take this to the finish line, but if you’ve gotten this far, you know how to do the rest!

Improve Symfony3 cache/logs performance by environment

Tired of the permission errors with your cache/logs in a Vagrant environment? Me too!

After being mildly annoyed with having to manually delete /var/cache and /var/logs repeatedly during “local” development, I decided to brut force matters into my own hands and solve this little annoyance once and for all. Ironically, Symfony 3.3 is addressing some of this, so it may be obsolete by then, but in the meantime…

What are we doing here?

  1. Define cache and logs directories for a specific environment.
    1. Wouldn’t it be awesome if we could customize these as parameters in the FrameworkBundle? Yes, yes it would!
  2. Write a simple CacheCommand that overrides the default cache:clear
  3. PARTY!!!!

Customize your getCacheDir and getLogDir methods by your environment

In my case, I typically use Vagrant/Virtualbox for local development, and Docker containers/bitbucket-pipelines for “test” while Production is a variety/flavor of AWS EC2 instances which have some additional flare.

Write a CacheCommand you can love and cherish forever and ever


Now you can enjoy life and all references to cache:clear will run your new and improved command that will also work noticably faster in Vagrant development environments; thanks entirely to Benjamin Eberlei and his wonderful blog post.


cd /path/to/myapp && php bin/console cache:clear

Vagrant `/sbin/ifdown eth1 2> /dev/null`

If you’re experiencing a fatal error when loading a Vagrant machine, chances are you just need to upgrade your version of Vagrant.

Specifically this error, when using ubuntu/xenial (Ubuntu 16.04 LTS)

Upgrade your local install of Vagrant to at least 1.8.5 and you’ll be set.