There are many options when it comes to setting up your computer for developing web applications. If you’re using Windows, I covered some of them here. However, in this post I’m going to focus only on Vagrant and Docker. This post is mainly targeted for Windows 10 users and for simpler projects that doesn’t involve multiple developers, complex environment and configuration. This is for developers who are mostly used to installing all of the dependencies directly on OS, without any kind of virtual machine, provisioning or containers. I assume if you’re reading this that you’re already familiar with basics of Vagrant and Docker and that you’ve used them.
Speed, convenience and simplicity
For many years I was using Ubuntu based Linux distribution as my working OS. I used package manager and installed everything I needed to run my PHP applications. And with little bit of configuration and tinkering I got a pretty fast, convenient and simple environment. I ran all of my PHP projects on same PHP and MySQL versions with same configurations. Now we focus more on easy deployments, automating tasks and easy 1-click installs. Also, on Windows 10 you’re kind of forced to use them. My previous setup was fast, convenient and simple and that’s my main benchmark when using Vagrant and Docker.
In my own non-scientific experience Docker is much faster option. Docker containers initialize much faster than Vagrant machine. Response times are better and running console commands feels faster. Vagrant relies on syncing folders between host and guest machine. This is a huge bottleneck on Windows and considering staggering amount of files per projects (thousands) it will be slow. Even with my high end machine and SSD (Dell XPS 15 and Samsung 970 EVO 500GB) Vagrant is slow. I did some optimizations (using winnfsd and bindfs plugins) and it’s still slow. Docker is noticeably faster and since I’m coming from running binaries natively on Linux I’m kind of spoiled in that regard.
Since I’m primarily aiming at one setup for all projects they are both pretty convenient options. They both require only one command for “switching on”. In this case Vagrant is less messy because it’s simpler to configure. I’ll be fair, they’re not really meant to be used this way. if you’re going to use per-project setup then Docker has the edge. They are both powerful and offer easy setup for everybody but Docker is scalable and is great for CI/CD setup. Conclusion: for monolithic development environment Vagrant is more convenient. For per-project setup Docker is much more powerful and can solve more problems.
If I want similar setup as before, to run all my PHP apps on same OS using same version and configuration, I think that Vagrant is simpler choice than Docker. There are many Vagrant boxes out there and many of them are fully configured for types of apps you develop. Some of them (like Homestead) even have simple and powerful custom configuration so you can easily add new projects and set them up in seconds. You could achieve something similar in Docker however I find configuring Docker containers a bit more complicated than Vagrant. There are preconfigured docker-compose.yml files (for instance Laradock) that set up all the possible dependencies you’ll need. You can use that kind of Docker setup very similarly to Vagrant. However you’re going to have to be pretty familiar with Dockerfile and docker-compose.yml.
Which one is better for development?
That depends on your preferences. My choice is Docker. Basically they are both great options for what I was looking for. But I can do more with Docker and I think it’s more valuable. Also, that speed boost is pretty nice and I don’t have to start Docker with admin rights for symlinks to work.