89luca89 / distrobox

Use any linux distribution inside your terminal. Enable both backward and forward compatibility with software and freedom to use whatever distribution you’re more comfortable with. Mirror available at: https://gitlab.com/89luca89/distrobox
https://distrobox.it/
GNU General Public License v3.0
9.78k stars 398 forks source link

[Feature] MacOS host support #36

Open dcorbe opened 2 years ago

dcorbe commented 2 years ago

Is this an effort worth exploring?

89luca89 commented 2 years ago

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

DanielTolentino commented 2 years ago

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

89luca89 commented 2 years ago

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)

goodevilgenius commented 2 years ago

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.

dcorbe commented 2 years ago

On Dec 29, 2021, at 09:26, Dan Jones @.***> wrote:

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

Docker also runs in a VM on Mac OS

If the goal is to containerize and not isolate, why not consider distributing a light-weight Kubernetes distribution with this project? Something like k3s or Minikube would work perfectly for this and it has the added advantage of being able to run on Windows, Mac OS and Linux.

89luca89 commented 2 years ago

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

89luca89 commented 2 years ago

Let's follow this as it's a blocker for now: https://github.com/containers/podman/issues/8016

WoMspace commented 2 years ago

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

89luca89 commented 2 years ago

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

kevindurb commented 1 year ago

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

jakenvac commented 1 year ago

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)

89luca89 commented 1 year ago

@JakeHL will investigate, I don't have a Mac so it might take some time :smile:

jakenvac commented 1 year ago

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

jacobnollette commented 1 year ago

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

stevo-knievo commented 1 year ago

1+

aral commented 1 year ago

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: https://github.com/containers/podman/issues/8016 :)

jakenvac commented 1 year ago

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 1 year ago

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

jakenvac commented 1 year ago

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.

kevindurb commented 1 year ago

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
kevindurb commented 1 year ago

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

kevindurb commented 1 year ago

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

89luca89 commented 1 year ago

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

kevindurb commented 1 year ago

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

kevindurb commented 1 year ago

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
jakenvac commented 1 year ago

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.

kevindurb commented 1 year ago

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"
kevindurb commented 1 year ago

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

kevindurb commented 1 year ago

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

Mount propagation doesn’t work with Docker Desktop.

Well theres that answer lol

kevindurb commented 1 year ago

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?

kevindurb commented 1 year ago

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 🎉

kevindurb commented 1 year ago

PR to get the installer working for macos https://github.com/89luca89/distrobox/pull/615

kevindurb commented 1 year ago

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)

89luca89 commented 1 year ago

I'm glad there is progress in this issue, thanks @kevindurb :smile: Hopefully I'll find a way to run macos in vm (laptop/cloud) and do some help :+1:

pythoninthegrass commented 1 year ago

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.

FedX-sudo commented 1 year ago

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

Soromeister commented 1 year ago

Any updates on this?

osalbahr commented 1 year ago

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.

osalbahr commented 1 year ago

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

redthing1 commented 1 year ago

I'm very interested in this too

tl87 commented 8 months ago

I would also really like for this to be a reality 👍🏻

kevindurb commented 8 months ago

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

kevindurb commented 8 months ago

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

Sahil-Gulihar commented 3 weeks ago

Has it been resolved?

osalbahr commented 6 days ago

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).

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

redthing1 commented 2 days ago

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

Sahil-Gulihar commented 1 day ago

Specifically designed and tested on mac

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

redthing1 commented 20 hours ago

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