top | item 38989019

Simulate an Ubuntu-like VM inside macOS

38 points| yashodhanmohan | 2 years ago |yashodhanmohan.medium.com

31 comments

order

js2|2 years ago

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.

yashodhanmohan|2 years ago

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.

fragmede|2 years ago

Not to mention, Parallels, VMWare, VirtualBox, QEMU

beeman|2 years ago

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/

intpx|2 years ago

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.

yashodhanmohan|2 years ago

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?

lioeters|2 years ago

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

Erratic6576|2 years ago

$ brew install multipass

j16sdiz|2 years ago

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

This docker-based solution looks needlessly complex.

yashodhanmohan|2 years ago

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.

ascendantlogic|2 years ago

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

freetime2|2 years ago

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

sgarland|2 years ago

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

rswail|2 years ago

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.

k_roy|2 years ago

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.

yashodhanmohan|2 years ago

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.

dakiol|2 years ago

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)

TheFuzzball|2 years ago

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

oujiii|2 years ago

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!

yashodhanmohan|2 years ago

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.

gbraad|2 years ago

I want a VM so I run a container?

pjmlp|2 years ago

> 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