For those looking for a streamlined, lightweight command line interface for Docker on Mac, look no further. Multipass is a flexible tool that makes it easy to create and run Ubuntu VMs on any platform, and it comes with built-in tools that make running applications like Docker feel native on platforms such as macOS.
What is Multipass?
Multipass is a command line tool that makes managing virtual machines a breeze. From giving you an Ubuntu shell in as little as less than 20 seconds, to creating local miniclouds for test and dev work, it has your Linux needs covered.
Why Run Docker in Multipass?
Multipass is designed to be lightweight, flexible, and efficient. It can run in the background unnoticed, available whenever you might need it.
Multipass has deep host integration, which is a game changer for an application like Docker. You can mount local files with a single command, giving you access to dockerfiles and source code kept in macOS. What’s more, you can alias Linux commands to the host machine, and make them context sensitive in that space. This becomes particularly useful for docker-compose.
Let’s say you have a docker-compose.yml file sitting on your host machine and you need a quick way to test it out. With Multipass, you can run `docker-compose up` directly from your host machine’s terminal, without ever needing to launch an application or shell into a virtual machine.
Multipass runs Docker inside a VM in the same way that other tools such as Docker Desktop do. Multipass, however, gives you control over that VM and any others you might need. Let’s say you need multiple instances of Docker with different configurations applied to each – you can do that with Multipass. Or perhaps you need a few different flavors of Kubernetes and associated applications to run in other VMs on the same local or external network – you can do that with Multipass too.
Docker on Mac with Multipass
Getting Docker running on Mac with Multipass takes just one command:
`multipass launch docker`
This creates a virtual machine with the latest Ubuntu LTS with Docker preinstalled. It also mounts a workspace, a shared file space between the host and the virtual machine so you can easily transfer data or source code between the two. Of course, if you have an existing folder you want to share, you can mount that after the fact, or modify the above command to something like this:
`multipass launch docker --mount=/path/to/my/folder`
These commands also create aliases for several docker commands: `docker` and `docker-compose`. To use them, you can either prefix them with `multipass`, or you can add the aliases to your path by following the instructions in the output of the above commands (typically something like `XXXX`).
Now, to create a container or run a docker-compose file, just run the command as if you had docker installed natively.
`docker build -t my-mac-container .` or `docker-compose up`
You should now be up and running with Docker.