How to run GUI apps in containiers in osx? (docker for mac)

I have read the guidelines to run GUI apps inside docker. But when it comes to Mac, all the guides rely on boot2docker or running docker inside a VM and forwarding the x11 using xquartz.

Since we have docker for mac now, is it possible to forward the video and audio directly without using xquartz or vnc?

From Jessie’s blog, in docker run command these are the parameters I am interested in.

docker run -it \
    -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
    -e DISPLAY=unix$DISPLAY \ # pass the display
    --device /dev/snd \ # sound
    --name spotify \
    jess/spotify

I am actually looking to pass the display and sound. Is it possible without using vnc or xquartz?

3 Likes

good question, I would really like to do the same. If possible without X11 forwarding. But no clue where to find informations.

1 Like

As far us I have explored, OS X doesn’t expose device files like /dev/snd or /dev/video. Also, there is no x11 client to expose it by default. So relying on xquartz or something like that is needed. I will explore further and update the thread

1 Like

I’ve done a little work to make remote desktop containers

https://github.com/deskor/xrdp is the base, and there are working examples of chrome and vscode in https://github.com/deskor

once running, I then connect from any of my computers using an remote desktop client.

When I next make time, I’ll make it more swarm mode aware :slight_smile:

1 Like

Thanks for those links. I am looking for a direct way of using GUI apps without any remote desktop client

OS X does not have X11 so you have to download and install XQuartz 2.7.8 (https://www.xquartz.org/releases/index.html).

Start XQuartz (open -a Quartz) before running your container, you may have to enable the option Security/Allow connections from network client. After that you can run your container and make sure that you have /tmp/.X11-unix mounted.

I am able to get Webstorm run in native Docker container this way.

Hope this helps

1 Like

I outlined a step-by-step on how to get GUI applications running under Docker for Mac here: https://fredrikaverpil.github.io/2016/07/31/docker-for-mac-and-gui-applications/

1 Like

I followed that guide, and it worked after I actually read that you need to either edit the startx script or use a beta version of Xquartz 2.7.10.

Anyway, I was wondering if it is possible in principle to make use of retina displays properly with Docker for Mac? Apparently under Xquartz this is an insurmountable barrier. Nonetheless, using Virtualbox it seems to be possible. Is this something that Docker for Mac could allow as well?

1 Like

Just replying to say I have no idea. I had a hard time finding a concrete step-by-step guide on just getting started and figured I’d share my findings.

1 Like

@fredrikaverpil, How did you run xhost + $ip command?

I stumbled on your StackOverflow question when googled on the same. My machine does’t have xhost command. Also, do I need to run the xhost + command on the shell that is running xQuartz?

Run the xhost command in the shell where you ran “open -a XQuartz”.

xhost + YOUR_IP_ADDRESS

My bad. I didn’t add it to the path. Firefox is up and running from container now :slight_smile:

@fredrikaverpil, after reading about xhost a little bit, it is unsafe to do xhost + $ip, as we will be using private ip addresses most of the time. It is better to add using hostname,

xhost + $(hostname)

or we have to remove the ip if we switch to another network or ip address gets renewed(to a new address) xhost - $ip

Hi, I’m trying to run your chrome container following your command in the xrdp readme:
docker run --name docker -v /var/run/docker.sock:/var/run/docker.sock -v /usr/local/bin/docker:/usr/local/bin/docker busybox true

Is the -v flag correct in this command? I get an error “mkdir /usr/local/bin/docker: file exists”

I’m very new to docker, so I’m sorry if I’m missing something trivial here.

-Ryan

These were pretty interesting. Though maybe not totally what I’m looking for.

I’d like somehow to provide a painfully simple installable app (think drag and drop) for end users. Basically it would be great if they could click on the app and behind the scenes it starts up a Docker container and opens a browser to an exposed port on the container. I expect this gets massive if I try to use things like VirtualBox. Preferably I’d like to use the Hypervisor.framework on Mac to provide this functionality to keep things lean. Are there any recommendations or suggestions for how one might go about bundling Docker up for this use case? Any other projects that might be relevant?

1 Like

Hey there, you may also want to try Nut: https://github.com/matthieudelaro/nut#what-the-nut

On debian, I’ve developed a related bash script:


Some of it features may be helpful on Mac, too.

  • Sound from docker containers is possible with pulseaudio over tcp. I’ve described it here: http://stackoverflow.com/a/39780130/5369403
  • All solutions for X forwarding base on a running X server, you will need XQuartz in every case. It is possible to use xpra and Xephyr to show single applications or desktop environments. Both are available for Mac.
  • Usage of xhost should be avoided due to possible security leaks. x11docker creates X server cookies for authentication with xauth and shares them with containers, this should be possible with XQuartz in the same way.
  • Maybe x11docker script can be adapted for Mac with slight adjustments.
1 Like

Can you please develop on how to edit the startx script?
I followed the step-by-step how-to, but nothing happened.

I was having issues with the socat command because the ${DISPLAY} file name ends in “:0” and socat thinks thats an extra argument.

So, I wrote the following which works for me… but no sound

VOLUMES="-v $HOME/Downloads:/root/Downloads -v $HOME/.config/google-chrome/:/data -v ~/.Xdefaults:/root/.Xdefaults  -v ~/.config/ff:/home/root/.mozilla/firefox "

ln -fs  ${DISPLAY}  /tmp/x11_display
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:/tmp/x11_display &
alias ff="docker run --rm  -it  ${VOLUMES} -e DISPLAY=$(ipconfig getifaddr en0):0.0  firefox"

You can also substitue firefox for tor, chrome etc.

Hello, could you please post what series of steps you used. I’m struggling here