Nitro 2: The Docker powered development environment for Craft CMS

Pixel and Tonic have recently released Nitro 2, a tailored development environment for Craft CMS. Previously version 1 was based off Multipass. Nitro 2 however is big shift being based on Docker. More importantly for me, thanks to Windows Subsystem for Linux 2 (WSL2), there is a smoother Windows environment option now available, albeit with some caveats. Let’s explore Nitro 2 and why you should consider using it with your Craft CMS projects!

1. It’s powered by Docker

With Nitro 2, you must use WSL2 and Docker for Windows support but there are good reasons for it, mainly performance. There are also a few worthy mentions of the best configurations when using Docker and WSL2. The good news is, WSL is available on any SKU on Windows, so no more Windows 10 Pro Hyper-V dependency, that means any Windows 10 version can use Nitro 2, providing you are using build 19042 or above, as this is when WSL2 was released outside of insider builds.

2. Easy and guided provisioning

The init command essentially creates the base Docker containers and pulls the required images needed. Here you get to configure one or more database backends i.e. MySQL, in addition to Redis and some other toys.

Fun fact, Nitro uses official Craft CMS docker images. I previously evaluated the Docker images themselves outside of Nitro first and found them to be nicely curated and configured, well suited to Craft CMS development.

The add command, is for configuring an actual Craft CMS site, setting a hostname, the PHP version etc. You run this in the root of a Craft CMS project.


$ cd /path/to/project
$ nitro add
Adding site…
Enter the hostname [mysite.test]:
✓ setting hostname to mysite.test
✓ adding site ~/dev/support/mysite.test
Enter the webroot for the site [web]:
✓ using webroot web
Choose a PHP version:
1. 8.0
2. 7.4
3. 7.3
4. 7.2
5. 7.1
6. 7.0
Enter your selection: 2
✓ setting PHP version 7.4
… saving file ✓
Site added 🌍
Apply changes now [Y/n]? y
Checking network…
✓ network ready
Checking proxy…
✓ proxy ready
Checking databases…
… checking mysql-8.0-3306.nitro ✓
… checking postgres-13-5432.nitro ✓
Checking mounts…
… checking ~/dev/craftcms/cms-3 ✓
Checking services…
… checking mailhog service ✓
Checking sites…
… checking mysite.test ✓
Checking proxy…
… updating proxy ✓
Modifying hosts file (you might be prompted for your password)
Adding sites to hosts file…
… modifying hosts file ✓
Nitro is up and running 😃

Currently Nitro 2 does not support a way to automatically provision an environment based off a yaml file in similar way to docker-compose.yml, but it’s a feature request and it’s coming soon! This is more useful for multi-dev environments or when you deploy a specific project across multiple operating systems/different machines. While Nitro makes it straight forward to provision sites, constantly being prompted the same specific answer values is slightly time consuming and hence a non-interactive method of provisioning is something I’m looking forward to!

3. Nitro 2 has lots of configuration options

I would recommend not using anything lower than PHP 7.3 due to the EOL status of anything below 7.3 at this time of writing.

The great thing with Nitro 2 is you can easily add or swap out various elements with simple commands. You can also run multiple database backends at the same time. Nitro does the heavy lifting behind the scenes and sorts out all the container configuration and requirements, leaving you to just get on and code, the dream!

4. You can run multiple sites without having to worry about port collisions!

This is a major bonus as the networking stack of Docker is notoriously difficult to manage manually and you can quickly get lost in some of the bridge, NAT and if you dare, complex VLAN configuration.

5. Automatic HTTPS

6. Nitro 2 works with Craft CMS 2 projects

Check it out for yourself!

Here’s some resources to start you off.

Some thoughts from other developers:

I'm a web developer, but also like writing about technical networking and security related topics, because I'm a massive nerd!