41

Recently Docker announced that Docker Desktop would cease to be free for some kinds of users. See announcement in blog post.

I don't need any of the features that are exclusive to Docker Desktop®. I have used docker in a laptop with debian on it and that version is good enough for me.

Is there a way to install the linux version of docker in macOS? I need both the engine and the cli tool, nothing more. I run build commands, push, tag, run, docker-compose, etc.

0

6 Answers 6

20

There is an alternative to docker, it is podman.

  1. Install: brew install podman
  2. Download and prepare the VM: podman machine init
  3. Turn on the VM: podman machine start
  4. Uses as a docker: podman run -d -p 8000:80 nginx
  5. Verify container: podman ps
  6. Interact with it: curl localhost:8000

It uses QEMU for virtualization underneath, and set a machine with Fedora CoreOS by default.

To access details of default machine and the virtualization environment after installation:

cat ~/.config/containers/podman/machine/qemu/podman-machine-default.json

8
  • 1
    sounds very feasible for my team! thanks, I hope I can make this work and even use docker-compose with it Oct 12, 2021 at 23:27
  • I am trying to install podman, but I am stuck in podman run ... I get errors about unexpected end of json file, etc. I am browsing the web to see if my issue is common Oct 14, 2021 at 14:20
  • 1
    I now tried in a new mac with m1, and I installed podman without ever going for docker desktop, this worked, at least for the easy scenarios (I haven't tried to docker-compose up, or mount volumes, or use gcr.io) Dec 21, 2021 at 12:55
  • 1
    so far I am liking this solution, however, I know there is a way of achieving a better outcome by combining minikube + hyperkit + docker-cli, I am reserving the accept until I see a working setup of this solution using M1 Dec 21, 2021 at 16:11
  • 3
    FAIL, podman doesn't support mounting local (macos) folders in the podman machine to use as mount volumes in a container Dec 21, 2021 at 16:54
16
+50

On my Macbook, I've installed docker via homebrew with

brew install docker docker-compose docker-machine xhyve docker-machine-driver-xhyve

(though this was way before docker desktop became non-free, but I'd assume it'd still work)

This uses xhyve as a virtual machine, so are basically running a Linux distro in xhyve, and then Docker in this Linux distro.

You need to do a bit of configuration, I followed this article.

My commandline for creating the VM was

docker-machine create default --driver xhyve --xhyve-experimental-nfs-share=true --xhyve-disk-size "40000"
4
  • 1
    following these steps I'm getting "Error creating machine: Error in driver during machine creation: Could not convert the UUID to MAC address: exit status 1" on macOS BigSur version 11.6 Oct 3, 2021 at 4:33
  • @AzatIbrakov please make a new question for this, but it's really difficult to do any kind of debugging on this Q&A site. "Exit status 1" suggests you need to debug some shell script in more detail to get an idea what step goes wrong, and why. So the first step is to figure out which shell script was executed.
    – dirkt
    Oct 3, 2021 at 4:55
  • 3
    Well, the xhyve driver is deprecated. Also the docker-machine project was deprecated by docker years ago, and the forked project is not under active maintenance has a while. I suggest to use podman as docker replacement. You can even alise docker to podman, it works almost the same way.
    – ruzenhack
    Oct 7, 2021 at 3:24
  • brew install docker docker-compose is still valid. I run Docker Engine in a Debian VM and SSH tunnel the docker socket between the macOS host CLI and Linux guest engine. I wrote about the setup here: codeluge.com/post/…. It is a similar technique to what podman and Docker Desktop do.
    – jmort253
    Nov 30, 2022 at 4:39
8

As far as I'm aware docker is functionally incompatible with MacOS. I have docker desktop running on my Macbook and to the best of my knowledge this is achieved by docker desktop creating a Linux virtual machine and running the Docker engine in that.

This explains why docker desktop has the concept of allocated resources including a "disk image size" which have nothing to do with docker engine itself.


Is there a way to install the linux version of docker in macOS?

No. Not without a Linux virtual machine. This is because Docker is a wrapper for namespaces and cgroups which are both Linux concepts with no implementation in the MacOS kernel.

Since these two features are the core of container technology you're highly unlikely to find other non-docker solutions (including Podman) will work either... unless you use a Linux virtual machine.


I don't need any of the features that are exclusive to Docker Desktop®

That may be the case, I don't know your needs. But be aware that you may be using some features of docker desktop that you didn't realise were "features". For example docker bind mounts are a core concept in docker, however to get them to work on your Mac, docker desktop must also take responsibility to bridge the gap between MacOS and the Linux virtual machine.


To run your own virtual machine you can look into using a hypervisor like Virtualbox to run your own linux virtual machine on your mac.

3
  • 1
    interesting, I certainly don't like the idea of adding Virtualbox, but it might be the only choice. I will wait and see if I (or someone else) can make it work with something like podman Sep 22, 2021 at 15:47
  • @santiagoarizti yeah I've just edited to reference podman. It says it works on mac if you use a Linux virtual machine. The trouble is containers are really only a Linux concept and always have been. Don't ask me about Windows Docker containers, I've never investigated them Sep 22, 2021 at 15:49
  • 1
    There are tools like Colima which automate the creation of a Mac OS virtual machine that runs the Docker engine. Under the hood, Colima uses Lima, which then uses the QEMU hypervisor. Aug 23, 2022 at 9:12
5

Another option I found was to install minikube.

Minikube will replace Docker's Kubernetes.

NOTE: There are some downsides on that.

brew install minikube

Then install pure docker via brew:

brew install docker

Hyperkit via brew:

brew install hyperkit

If you prefer you can use also Virtuabox instead of hyperkit. More details, see documentation from Minikube.

2
  • 5
    Clarifying the downsides either directly or at least with a supporting link would improve the answer, as would linking the Minikube documentation. Sep 27, 2021 at 9:19
  • I tried to fix the typo, but insanely, SE wants at least 6 characters of edits. Nov 4, 2021 at 22:08
3

When Docker announced that Docker Desktop would no longer be free, I did some research on alternatives and figured out how to run Docker Engine in a Debian VM while using the Docker CLI on the macOS host. I documented the instructions for doing this on a Mac M1 here in my article titled Setting Up Docker on macOS M1 Arm64 to Use Debian 10.4 Docker Engine.

Originally, I was simply using the Docker CLI that came with the pre 4.0 free Docker Desktop, but in November 2022 that is now a really old and outdated CLI, so to install the Docker CLI without Docker Desktop, use brew:

$ brew install docker docker-compose

Afterwards, I needed some kind of VM to run Linux in. If you're on an Intel Mac, you have many options from VirtualBox and more, but on ARM M1 Macs, the best free solution available at the time is UTM. I downloaded a Debian VM from their template gallery and then followed the instructions on Docker's website to install Docker Engine on Debian:

Remove old Docker components and Setup Repository - Run this inside the Debian VM

$ sudo apt-get remove docker docker-engine docker.io containerd runc

$ sudo apt-get update

$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

$ sudo mkdir -p /etc/apt/keyrings

$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine and Docker Compose in Debian VM

The final step is to then install the latest version of Docker on Linux:

$ sudo apt-get update -y && sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Install openssl-server on the VM

To connect the host CLI to the VM, I had to use SSH port forwarding to connect a socket on the host to /var/run/docker.sock. You need to install and configure SSH on the Debian server and open a port from the UTM settings so the host can connect through the network to the VM's SSH port. In UTM, I forwarded host port 22022 to guest port 22, so in the below steps, you'll see references to port 22022.

From the Debian VM:

$ sudo apt-get update -y && sudo apt-get install openssl-server

Connecting the host CLI to the VM and Running a Container

When running Docker in this manner, I then created an SSH tunnel between the host and the VM, and I set DOCKER_HOST to point to the connected socket:

Run on macOS Host:

$ ssh [email protected] -p 22022 -N -L/tmp/docker-on-debian.sock:/var/run/docker.sock ssh://[email protected]

$ export DOCKER_HOST=unix:///tmp/docker-on-debian.sock

This step must be done anytime you reboot the VM to re-establish connectivity. We can automate it with a bash script. I created a series of bash scripts in this dockerdeb repository for this purpose.

The other thing that doesn't happen automatically is opening ports the containers are listening on. You can do this via the VM, but I've found it much more convenient to again use SSH port forwarding for this so that I don't need to shut down the VM to reconfigure it.

For instance, if I want to run a container listening on port 4444, I need to also create a tunnel:

Run on macOS Host:

$ ssh [email protected] -p 22022 -N -L4444:127.0.0.1:4444

Then run the container.

Run on macOS Host:

$ docker run --rm -it -p 4444:4444 --shm-size 2g seleniarm/standalone-chromium:latest

To confirm the port is open, I can curl -L http://localhost:4444/status and retrieve a 200 OK response.

Disclaimer

For many things, I use podman and podman-machine without too many issues. However, this Docker/Debian VM setup has come in handy for situations where Podman falls down. For instance, I prefer to build multi-arch containers with Docker's buildx, since it's what we're using on the CI server. So when working locally, I use this Docker setup with the UTM VM so that I'm comparing apples to apples.

I don't believe this is the easiest way to run Docker on a Mac. For many common use cases, one of the other answers may be sufficient. However, if you want to learn about how Docker works behind the scenes, try running it on your own in a VM, and I promise you'll come away with a better understanding.

2

As suggested by a comment on one of the solutions, you can use a tool like Colima. (Github link)

You can install brew install docker docker-compose kubectl kubectx as normal and then install and start Colima - this will create a VM on MacOS on which docker/kubernetes can then run.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .