89luca89/distrobox

[Feature] MacOS host support

Opened this issue Β· 48 comments

Is this an effort worth exploring?

Yea I would like in the future to support it, what blocks me for now is the host integration

On MacOS podman runs in a VM, and distrobox integrates with the container's host, which in this case will be the VM, not the MacOS host
So it becomes quite a limited experience, without exports of stuff or graphical apps integration

I'm gonna keep this issue for the future and mark it ad blocked until we either find a solution or we create a piece of documentation that explains the situation and does not confuse the users

Ironically I think (not tried yet) that distrobox on WSL2 could retain some real host integration seeing how the linux VM is tightly integrated with the Windows host 🀷

Yea I would like in the future to support it, what blocks me for now is the host integration

On MacOS podman runs in a VM, and distrobox integrates with the container's host, which in this case will be the VM, not the MacOS host So it becomes quite a limited experience, without exports of stuff or graphical apps integration

I'm gonna keep this issue for the future and mark it ad blocked until we either find a solution or we create a piece of documentation that explains the situation and does not confuse the users

Ironically I think (not tried yet) that distrobox on WSL2 could retain some real host integration seeing how the linux VM is tightly integrated with the Windows host 🀷

Tried with an Ubuntu WSL install, got an error, I'll try other distros later.
image

Yea as said I didn't try πŸ˜‚
Anyway that seems an incompatibility between wsl2 and podman probably? Maybe there are some guides for it
Distrobox works with docker too I think that shouldn't have problems

Anyway I'd stick this conversation to macos and in case there is interest open a new one for WSL2
(I doubt WSL1 will work)

I just discovered distrobox, and this was the first thought I had. I have to use a Mac for work, but would love to be able to use this for a bunch of stuff.

Although podman might be difficult, maybe docker would work better, due to it's somewhat better integration into the host with HyperKit (hypervisor).

I'm not really sure of the specifics of how that works, but it might be a consideration.

All of them share the VM problem anyway, podman docker k3s, minikube all work inside a linux VM
I think it would be doable as a way to have something to have pet containers for dev environments, but I see it difficult to have the level of integration that can be achieved on a Linux host

Let's follow this as it's a blocker for now: containers/podman#8016

My two cents are that I'd love to have distrobox on macOS regardless of the lack of integration, as an easy way to automatically spin up lightweight VMs for various uses.
I love WSL on windows and just installed distrobox on a linux machine and it's amazing there too, would love to have some analogue on macOS

Well the point of toolbox/distrobox type of software is the tight integration with the host
If I cannot provide this integration it's just like using podman/docker

On MacOS right now I'm not even sure graphical apps can work inside distrobox with podman-machine

While i totally agree that tight integration with the host is what makes distrobox amazing i think there is some amount of usage for macos... I wanted to work on my personal distrobox container today and didnt have my linux machine near by and ended up doing podman build... and podman run... to be able to mess with it a little... but the problem is i still didnt have my user setup correctly as distrobox automagically does for me... but i also would rather not add a massive amount of bloat to this project just to support a weird usecase... this project is so fantastic already id hate to taint it with an extra chunk of bloat to have to maintain...

It might be worth investigating colima and/or lima for macos support rather than podman as it offers tighter integration with the OS out of the box. (Still a vm however)

@jakeHL will investigate, I don't have a Mac so it might take some time πŸ˜„

I daily drive an m1 macbook, Let me know if I can be of help. I'll take a look in the meantime. Would love to see this up and running

This would be increadible - mac os is the only option at work

aral commented

Let's follow this as it's a blocker for now: containers/podman#8016

Heads up, looks like that blocker is now closed on the podman side of things: containers/podman#8016 :)

I think podman honestly just over complicates things. Lima should be perfect for something like this - it allows for invoking commands inside a VM, sharing state between host and VM etc. Honestly its not far from doing what distrobox already does. Ive started to play with it to create a distrobox like experience and its been pretty great. Ive not tried integrating actual distrobox yet though.

aral commented

@jakeHL Hey Jake, is your work available somewhere to play with? Sounds very useful :)

Its not, its just crappy shell aliases and functions to try and recreate the behavior. If I can get some time over the holiday break I'll tidy it up and push it.

ok so i started messing with getting distrobox installed on macos, the install script uses install which is a different version from what is on macos so i did brew install coreutils and then replaced install with ginstall to get all the distrobox scripts put into place, that worked... So that would need to change in some way for mac compat

Next problem is when i go to run distrobox create I get this:

Error: failed to connect: dial tcp [::1]:51787: connect: connection refused

An error occurred

An error occurred

lol that error was because I didnt have my podman machine running πŸ€¦πŸ»β€β™‚οΈ... more errors on create using podman Error: statfs /Users/kevindurbin/.local/bin/distrobox-export: no such file or directory... testing docker...

container stays stuck in CREATED... I think its due to performance of mounting all of ~ with macos docker...

lol that error was because I didnt have my podman machine running πŸ€¦πŸ»β€β™‚οΈ... more errors on create using podman Error: statfs /Users/kevindurbin/.local/bin/distrobox-export: no such file or directory... testing docker...

Yes, this is because some parts of distrobox (init, host-exec, export) are mounted inside the container itself
In case of lima and other VM based solutions (which includes docker), the path of distrobox is not present, nor the same as inside the VM
So this will create errors

Podman on macos is also a VM based solution. I dont know of any container system that doesnt run on a vm on macos.

Ok so back to this... im on an M1 mac running ventura now and ive got the experimental rosetta 2 emulation and virtio (docker btw)... I think this is the best chance we have to make this work performantly. create works great and then when I enter i get the following error

Container dev is not running.
Starting container dev
run this command to follow along:

 docker logs -f dev

Error response from daemon: path /host_mnt/private/tmp is mounted on /host_mnt/private but it is not a shared or slave mount
Error: failed to start containers: dev

Yes, this is because some parts of distrobox (init, host-exec, export) are mounted inside the container itself...

What is the path it should be mounted at? Lima has great mounting options to share filesystems between host/guest. I'll see if I can get it working.

looks like theres an extensive list of volumes that get added, if you look at distrobox-create generate_command() function you can see it add all the volumes in. heres the initial list, i assume that /tmp is the one associated with the error, gonna attempt to just not mount this... but i'm also wondering if theres something broken with macos and rslave mounts...?

		--volume /:/run/host:rslave
		--volume /dev:/dev:rslave
		--volume /sys:/sys:rslave
		--volume /tmp:/tmp:rslave
		--volume \"${distrobox_entrypoint_path}\":/usr/bin/entrypoint:ro
		--volume \"${distrobox_export_path}\":/usr/bin/distrobox-export:ro
		--volume \"${distrobox_hostexec_path}\":/usr/bin/distrobox-host-exec:ro
		--volume \"${container_user_home}\":\"${container_user_home}\":rslave"

yea it seems like theres something macos doesnt like about rslave mounts... i have no clue what an rslave mount is so gonna do some research to see what this does and maybe theres an alternative for macos

https://docs.docker.com/storage/bind-mounts/#configure-bind-propagation

Mount propagation doesn’t work with Docker Desktop.

Well theres that answer lol

ok so i was able to enter the container πŸŽ‰
I removed the following mounts: /, /dev, /sys, /tmp and changed the user home mount to not have rslave bind propagation, when i ran distrobox enter the first time it said Starting container... then exited silently. I ran it a second time and it dropped me into my container! So maybe with macos we could have a limited functionality mode or maybe something like lima can do bind propagation?

overall that means that if you remove some mounts and change the home mount to be a "regular" (shared?) mount and change the installer to use ginstall then you can have a limited functionality working distrobox on macos πŸŽ‰

PR to get the installer working for macos #615

Updated my pr to also add the changes to get create working. With those changes distrobox now works on macos in a more limited capacity (no /dev for device support, etc)

I'm glad there is progress in this issue, thanks @kevindurb πŸ˜„
Hopefully I'll find a way to run macos in vm (laptop/cloud) and do some help πŸ‘

Lost my original draft Ugh! Clearly need more coffee, but I might be able to get you a 2017 x86 MacBook Air from work @89luca89.

Or I can test whatever you want on either a runner or locally β€” have access to a number of x86 and arm64 Macs.

Potentially stupid question: How feasible is it to add MacOS support using something like Docker-OSX?

Any updates on this?

I daily drive an m1 macbook, Let me know if I can be of help. I'll take a look in the meantime. Would love to see this up and running

Same here, except I daily drive an Intel-based MacBook. Would love to help port distrobox to macOS, let me know if there is anything I should try. I’d like to have a distrobox with development tools in the same seamless way. I don’t know if being able to export is a main feature.

I created Homebrew/discussions#4603 and hopefully getting a fully functional brew install distrobox on Linux would make porting to macOS easier

I'm very interested in this too

tl87 commented

I would also really like for this to be a reality πŸ‘πŸ»

just fyi for those that want this ive just tested running distrobox in lima and i think thats the solution here. No matter what way you run containers on macos they run in a vm (docker, nerdctl+lima, podman, etc) so the easiest way to run distrobox on macos is:

limactl start
lima sudo apt install distrobox
lima distrobox create
lima distrobox enter ...

and then you're in a distrobox "on" macos (technically distrobox on ubuntu vm on macos), tested on apple silicon. The one oddity ive found is sometimes i need to distrobox enter twice cause for some reason i havent investigated the first fails silently. Also by default lima mounts the host's home dir to /Users/[username] inside the vm so its not the home dir as the user in the vm. but thats a simple config change

If anything it might be cool to add a lima.yaml to this repo that does the mount and installs distrobox automatically

Has it been resolved?

Has it been resolved?

As of now, Homebrew lists distrobox as Linux-only, so I guess not.

This was also confirmed in March, 2024, in a Homebrew discussion: https://github.com/orgs/Homebrew/discussions/5190 (at least on M1, no official support for distrobox on macOS). To be clear, this is not Homebrew's issue to fix, it's just an easy status check.

@Sahil-Gulihar This issue remains open if you would like to work on it. You'll probably have to do some form of a limited-features, container-in-container solution, which I don't know the use case for that compared to directly using containers (what I personally ended up doing, it's a good-enough workaround for my use).

  • Relevant discussion: #1021

(I'm no longer interested in actively working on it, but would be happy to try to help if you run into an issue)

To anyone who's interested in this: I wanted something like distrobox for a long time, after switching to a mac.
So I wrote my own minimalist implementation of something like distrobox. You define your linux box environment using a dockerfile (samples provided), then you can seamlessly mount your home/user directories in, so you can work on them directly but from a linux terminal.

Specifically designed and tested on mac but also will work anywhere supporting docker/podman. If you want to use docker instead of podman just Ctrl+F replace, it works with both.

I hope this is useful to others who switched to mac and miss distrobox!

https://github.com/redthing1/mim

Specifically designed and tested on mac

Does it solve the issue of accessing GUI apps from host system to the docker/podman?

Specifically designed and tested on mac

Does it solve the issue of accessing GUI apps from host system to the docker/podman?

You can X11 forward, its quite straightforward. Here's a guide: https://gist.github.com/sorny/969fe55d85c9b0035b0109a31cbcb088