Hacker News new | past | comments | ask | show | jobs | submit login
Simulate an Ubuntu-like VM inside macOS (yashodhanmohan.medium.com)
38 points by yashodhanmohan 9 months ago | hide | past | favorite | 31 comments



This reads a bit like "when all you have is a hammer" because it seems like what you want is a VM, not a container[^1]. Have you considered using VM software instead of Docker and using an Ubuntu VM directly? Some options:

https://mac.getutm.app/

https://tart.run/

https://orbstack.dev/ (using its "machines" functionality)

[^1]: Of course macOS docker is running a Linux VM under-the-hood, but that's an implementation detail.


I have used VM softwares before and would have preferred using them in all honesty. This was more of an exploratory "can I do this? if yes, how far can I take it?" exercise. I just wanted to see how much effort would it take if I just wanted to "simulate" stuff (turns out 4 measly scripts). Plus I already use Docker in my work. This helps me avoid installing the VM software separately.


About OrbStack's machines:

> Strictly speaking, OrbStack machines are not independent VMs, but they're virtually indistinguishable for most intents and purposes — just with better integration. This is why we choose to call them "machines".

https://docs.orbstack.dev/architecture#linux-machines


Not to mention, Parallels, VMWare, VirtualBox, QEMU


UTM (GP's first link) is a GUI on top of QEMU.

Well, that plus the native macOS hypervisor framework as of a few months ago.


Last I tried Vritualbox isn't reliably available on M1


I have been using Multipass [0] for a while and it works great to quickly spin up an Ubuntu environment on my MacBook. It supports cloud config in case you want a custom instance.

It seems to be limited to running Ubuntu instances only (at least, I haven't figured out how to run other Linux instances) but if you want a quick clean Ubuntu VM I would recommend it.

0: https://multipass.run/


Multipass is pretty clutch for trivial VMs on MacOs for sure. I use it for a bunch of ssh jump boxes running vpns to different sites. The macOS build does not support custom images (lest not without [some truly insane hacks](https://github.com/canonical/multipass/issues/1260#issuecomm...) , which doesn’t really matter for what I use it for but it is kind of a bummer. If you need something with a little more grunt but don’t want to go full blown with writing your own QEMU tooling or fussing with something like UTM or Parallels, [quickemu](https://github.com/quickemu-project/quickemu) is a really nice qemu wrapper with sane defaults that can expose a whole lot of power if you need it.


This looks quite interesting! Much more elaborate in options I guess. Though the limitation to Ubuntu is something they should look into expanding. Does it also allow me to persist state?


> Does it also allow me to persist state? You mean snapshots like a real vm? No, and thats why I don't use it.

Edit already, since I was wrong

https://discourse.ubuntu.com/t/multipass-snapshot-command/39...


I second this recommendation. Multipass is a convenient cross-platform way to run Ubuntu VMs.


Would love if Multipass could extend to other UNIX flavors as well.


On Linux you can specify any cloud-init qcow2 image with file:// or http(s):// and it works beautifully


$ brew install multipass


Leeloo Dallas Multipass


Why "stimulate" an Ubuntu-"like" VM when you can have real Ubuntu in a real VM?

This docker-based solution looks needlessly complex.


Just to see if I can. Just a small weekend exercise. "Complexity" might be subjective though, but then again it looks simple to me because I made it, so I might be excessively biased.


I tend to use https://lima-vm.io/ these days when I need a quick VM environment locally on my laptop.


Lima is what I use as well. It's quick and easy to just fire up a VM with default settings, but also very easy to configure with different file sharing options, port forwarding, different linux distributions, etc. (their examples are also pretty good IMO [1]).

In particular I use it to run an amd64 VM, which I need to run a stubborn service for work that doesn't run on arm CPUs.

[1] https://github.com/lima-vm/lima/tree/master/examples


From TFA, the author mentions things like `date` having different args on Mac (BSD utils) and Linux (GNU utils). While true, you can just install GNU utils on a Mac, and get access to all of those, prefixed by g (e.g. GNU sed is launched with gsed).

Linuxify [0] is a decent shell script that does all of this for you.

[0]: https://github.com/darksonic37/linuxify


If you use Macports (much more consistent than homebrew and much more attentive to the way MacOS works and MacOS SIP etc works) then installing the GNU utils ports gives you a standard GNU environment, so pretty close to Ubuntu/Fedora etc.

Of course, networking etc and DNS and other system services will be the native MacOS, but MacOS is a Unix. It has its own init with launchtl and DNS/mDNS with scutil and mDNSResponder.


If you already use homebrew, that works too: https://github.com/Homebrew/homebrew-core/blob/3ef7d3e13549b...


You can also do the same thing just with homebrew. I regularly replace a number of CLI utils because the BSD alternatives often have silly defaults/incompatible changes

No gsed, just sed.


Yeah, the script is just calling brew install over a list anyway.

I also outright replace sed and awk with their GNU equivalents. Better options and behavior, IMO. The only downside is if you have to share a script with someone, and then have to figure out how to make it work with stock.


Yep, used to use linuxify a few years back. But then it used to mess with my internal scripts. Anyhow, this was just a "what-if" exercise. Plus, Ubuntu was a test OS, but CentOS/RHEL were real PITA on client systems and this gives me a quick way out from spinning up a VM while still maintaining control. But agreed, if I just wanted GNU utils, I'd have just gone ahead with linuxify.


I use multipass to run Ubuntu VMs on macos (m1). It works flawlessly. Zero issues so far (I keep around 3 or 4 VMs running in the bg and they still work after days/weeks with no issues regarding the network or whatever)


A big flaw in this approach is that the `ubuntu:latest` VM is not necessarily the same userland as a real Ubuntu installation (e.g. Ubuntu Server 20.04 != ubuntu:20.04).


Could this be used to spin up older os x (and older Linux and Windows)? Or would any of the other services do that? Would be really nice for my work!


Anything that has a base Docker image available, this would work. RHEL, Debian, etc should work without much effort. I have not seen older OSX Docker images so probably not. Windows server does offer some base docker images.


I want a VM so I run a container?


> There are times, when you’re working on a remote system that has a Unix system like Ubuntu, RHEL, etc.

While on a certified UNIX system, naturally the solution is to use a VM. /s




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: