Your submission was sent successfully! Close

You have successfully unsubscribed! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates about Ubuntu and upcoming events where you can meet our team.Close

Docker on Mac – a lightweight option with Multipass

Nathan Hart

on 15 August 2023

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

If you haven’t yet, install Multipass either via the installer or with brew.

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.

For example:

`docker build -t my-mac-container .` or `docker-compose up`

You should now be up and running with Docker.

Further reading

To learn more about how this works in Multipass, read up on Blueprints or create your own. Leave us a note in Discourse if you have a cool project you want to share or if you’ve got feedback.

Talk to us today

Interested in running Ubuntu in your organisation?

Newsletter signup

Get the latest Ubuntu news and updates in your inbox.

By submitting this form, I confirm that I have read and agree to Canonical's Privacy Policy.

Related posts

BT Group and Canonical deliver 5G to UK stadiums

Canonical teamed up with BT to improve connectivity in football stadiums. Find out how we brought 5G coverage to Watford stadium.

Faster AI application development with Canonical and NVIDIA AI Enterprise

Ubuntu KVM support comes to NVIDIA AI Enterprise Canonical continues to expand its collaboration with NVIDIA by providing Ubuntu KVM Hypervisor support with...

What is a hypervisor? A beginner’s guide

In the realm of virtualisation and cloud computing, the hypervisor is a critical component that enables the seamless operation of multiple virtual machines...