Dart and Docker: Like Peanut Butter and Chocolate

Some things just belong together

Long story short: I needed a quick prototype to slurp up a yaml file and call the REST Policy API of OpenAM. There a bunch of languages that will get the job done, but being in a hurry (demo next week!), I wanted something that was super productive with great tooling. I chose Dart FTW!

To run Dart you need to install the VM . This isn’t a big deal as there are packages for Linux, Mac and Windows, but it adds a bit of extra friction to the process. Enough to turn some people off from the notion of using Dart.

Enter Docker. It turns out it is embarrassingly simple to create a Docker image that will package up your Dart project into a container. Here is the entire contents of the Dockerfile for my sample project:

FROM google/dart-runtime

Place that Dockerfile in your Dart project, and type

docker build -t my-cool-dart-project .

done like dinner.

The dart-runtime image has a couple of conventions that make this super easy. The entry point is assumed to be bin/server.dart, and any web service will be listening on port 8080. You can of course override those defaults.

The docker build hooks take care of downloading and bundling all of the dependencies (pub get) for your project. You (or your buddy, who assumes Dart is just too hard to install) can now run the project using docker:

docker run -p 8080:8080 my-cool-dart-project

This isn’t rocket science, but the “aha” moment that struck me is that docker levels the playing field for languages by taking care of deployment concerns. Neat stuff.