Can I use my GPU from a docker container on a MacBook Pro ? (AMD Radeon GPU) - macos

I would like to run a GPU enabled app (Gazebo) inside a docker container on my MacBook Pro.
I seemed to me, through my research, that about a year ago, Docker released a native Docker app for MacOS.
Before that, Docker used to spawn an entire Linux VM and run the container on top of it.
Now, it apparently uses some native hypervisor framework, making it more optimized and closer to the hardware, changing entirely Docker's approach to containerization on a Mac.
All this is not very clear to me and I am not sure of everything I stated.
Is it now possible to use my macbook pro's GPU from a docker container, and, if yes, how ?
The command line I'm using right now, which works for regular X11 apps but not GPU-enabled apps like Gazebo is:
xhost +
docker run -it -e DISPLAY=$ip:0 -v /tmp/.X11-unix:/tmp/.X11-unix image_name bash

There's still a virtual machine involved.
Docker for Mac uses a virtualization layer called XHyve. It's a lot thinner and more lightweight than VirtualBox or such (emulates fewer peripherals), but it's still virtualization.
PCI passthrough is (theoretically) possible, but you can't pass through your laptop's main GPU and still use it.
Hardware with an IOMMU (and yes, your MacBook Pro has an Intel chipset with such support) can allow a virtualized environment direct access to PCI hardware.
However, you can't cede control of a piece of hardware to a VM and still use that hardware from the host. (Some high-end server network cards work around this by having multiple PCI endpoints, so the host and each guest gets a different endpoint to talk to).
So -- you could get an external Thunderbolt-attached GPU, and it might work... in the future.
The underlying support in Xhyve isn't there yet (as of this mid-2017 writing), and even on KVM (used by a lot of folks doing pioneering work here), there are only limited reports of success (with a specific video card -- the Radeon HD 5850).

Related

Performance issues on WSL 2

For the last two months I've (tried to) embraced WSL2 as my main development environment. It works fine with most small projects, but when it comes to complex ones, things start to slow down, making working on WSL2 impossible. With complex one I mean a monorepo with React, node, different libraries, etc. This same monorepo, on the same machine, works just fine when running it from Windows itself.
Please note that, when working on WSL2, all my files are in the linux environment; I'm not trying to access Windows files from WSL2.
I've the latest Docker Desktop installed, with WSL2 integration and kubernetes enabled. But the issue persists even with Docker completely stopped.
I've also tried to limit the memory consumption for WSL2, but that doesn't seems to fix the problem.
My machine is an Aero 15X with 16GB of ram. A colleague suggested upgrading to 32GB of ram. But before trying this, or "switching back" to Windows for now, I'd like to see if someone has any suggestions I could test out.
Thanks.
The recent Kernel version Linux MSI-wsl 5.10.16.3 starts slower than previous overall.But the root cause can be outside WSL: if you have a new NVIDIA GeForce card installed Windows gives it to eat as much memory as it can, i.e 6-16 Gb without using it. I had to limit WSL memory to 8Gb to start WSL service without OoM. Try to play with this parameter in .wslconfig in your home directory and look at the WSL_Console_Log in the same place. If the timestamps in this file are in ms my Kernel starts in 55 ms and then hangs on Networking(!!!).
I'm afraid that WSL Kernel network driver
lshw -c network
*-network
description: Ethernet interface
physical id: 1
logical name: eth0
serial: 00:15:5d:52:c5:c0
size: 10Gbit/s
capabilities: ethernet physical
configuration: autonegotiation=off broadcast=yes driver=hv_netvsc driverversion=5.10.16.3-microsoft-standard-WS duplex=full firmware=N/A ip=172.20.186.108 link=yes multicast=yes speed=10Gbit/s
is not so fast how it is expected to be

Running metal-enabled app on macos virtual machine

Is there any virtualization solution that supports metal api?
We have an app that uses Metal internally, and we'd like to test it across different macOS versions. Unfortunately it seems that VirtualBox, Parallels Desktop & VMWare Fusion doesn't enable Metal API in their guest macOS.
How can we test the app without having multiple physical machines or without using dual-boot?
UPDATED ANSWER 2019
Parallels Desktop v. 15 finally uses Metal. See their blogpost.
ORIGINAL ANSWER:
As far as I researched there's no chance of doing so with virtual machines.
The only feasible work-around we found is to:
find/purchase hi-speed USB drive (or even external SSD)
install various macOS versions on partitions of the USB drive
boot your Mac from the pendrive and select the OS you want to test
Not ideal, but does the job.

Is it possible to access a hardware device with a Docker image under Windows?

Recently, a native Docker client for Windows was released (>= Windows 7).
I wonder: is it possible to forward access to physical devices, running Windows as host?
With a *nix host, this seems to be possible with the following syntax:
docker run -t -i --device=/dev/ttyUSB0 ubuntu bash
(as proposed here) which would forward the USB device /dev/ttyUSB0 on a *nix system to the docker image.
A description of the --device flag can be found in the docker docs.
What would be the syntax for a Windows host?
Windows USB devices are not currently available to Docker containers run with Docker for Windows.
Answered by a Docker staff member on the 7th of July 2017 in the Docker forum.
https://forums.docker.com/t/exposing-docker-to-usb-device-in-windows-10-with-docker-toolbox/29290/3
This answer is likely to get outdated in some time, provided they will allow for this feature somehow.
This is a bad practice as it goes against the design philosophy of containers.
If you find yourself needing access to a hardware device, it's better to consider full virtualization such as VMware, Hyper-V, KVM/QEMU, Xen and so on.
However, the "proper" way is to design your system
so that hardware is abstracted into a network service. In this way, you deploy the service to physical machines to which the hardware is attached, and call them over the network. I don't know if this is possible in your case, but such decoupling provides a significant architectural advantage.

Is there an App-V / Docker equivalent for Mac OSX?

Windows has a application-virtualisation tool called App-V.
Linux appears to have a similar tool called Docker.
My question is - is there a Docker equivalent for MacOS X? (ie without having to spin up a Linux virtual machine on VirtualBox?)
There is no strict analog for OS X. If you are against spinning up a virtual Linux machine, your options are:
A simple chroot jail. The jailkit utility can help you out with this.
For your own OS X applications, using App Sandbox to limit the resources your app has access to.
Again, neither of these is just like Docker 0.x, which uses LXC under the covers.
The chroot solution is closer, since it is one of the components that LXC is built on. However, it doesn't provide kernel namespaces or anything like cgroups — both of which are two very important parts of LXC.

Why can't you install docker natively in osx?

I would love to be able to use docker outside of Vagrant in OSX. Right now this is not possible. What are the specific reasons causing it not to be limited for linux installations only?
Docker is just an abstraction & automation layer on top of system-provided containers.
The technical limitation is that OS X does not support operating system-level virtualization, like containers in Linux or jails in FreeBSD (even despite the fact that OS X is a half-blood BSD).
But even despite that, Docker aims to provide an easy way to share container images, and to make sure that any Docker image would work on any Docker-compatible system, they had to limit it only to Linux. (That is probably why Docker doesn't support FreeBSD and friends, which do have containers.)
UPDATE: you can use projects like docker-osx or boot2docker to enjoy Docker on your OS X machine almost seamlessly (both create a Linux virtual machine behind the scenes.)

Resources