Categories: BlogCanonicalUbuntu

Docker on Mac – a lightweight option with Multipass

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
Sponsored
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:

Sponsored
`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.

Ubuntu Server Admin

Recent Posts

Web Engineering: Hack Week 2024

At Canonical, the work of our teams is strongly embedded in the open source principles…

4 hours ago

Ubuntu Weekly Newsletter Issue 873

Welcome to the Ubuntu Weekly Newsletter, Issue 873 for the week of December 29, 2024…

2 days ago

How to resolve WiFi Issues on Ubuntu 24.04

Have WiFi troubles on your Ubuntu 24.04 system? Don’t worry, you’re not alone. WiFi problems…

2 days ago

Remembering and thanking Steve Langasek

The following is a post from Mark Shuttleworth on the Ubuntu Discourse instance. For more…

2 days ago

How to Change Your Prompt in Bash Shell in Ubuntu

I don’t like my prompt, i want to change it. it has my username and…

2 days ago

The Silent Guardian: Why Bundler Checksums Are a Game-Changer for Your Applications

Introduction: A Fragile Trust The Ruby ecosystem relies heavily on RubyGems.org as the central platform…

3 days ago