How to forward Docker for Mac to X11? - macos

Using Docker for Mac 1.12 (stable) and OS X 10.11.5 (15F34), I'm attempting to make one of my containers forward to X11.
First, I install XQuartz from my bash shell:
$ brew cask install xquartz
==> Downloading https://dl.bintray.com/xquartz/downloads/XQuartz-2.7.9.dmg
######################################################################## 100.0%
==> Verifying checksum for Cask xquartz
==> Running installer for xquartz; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
==> installer: Package name is XQuartz 2.7.9
==> installer: Installing at base path /
==> installer: The install was successful.
🍺 xquartz staged at '/usr/local/Caskroom/xquartz/2.7.9' (73M)
Then I continue with setting up XQuartz...
open -a XQuartz
In the XQuartz Preferences -> Security tab, I enable "Allow connections from network clients".
Then I am supposed to run xhost + $MY_IP_ADDRESS in my bash shell, but all I get is this error:
xhost: unable to open display ""
In the end, all guides I'm reading says I should run my container like this:
docker run -e DISPLAY=$MY_IP_ADDRESS:0 -v /tmp/.X11-unix:/tmp/.X11-unix DOCKER_IMAGE
...but that doesn't work. In my particular container, I get this error:
... cannot connect to X server 10.0.0.131:0
What am I doing wrong?

Turns out there's a bug in XQuartz 2.7.9.
When using XQuartz 2.7.10_beta2, it works.

I have xQuartz 2.7.11 installed on Mac OS.
I was getting the following error
<program>: cannot connect to X server <ip>:0
when trying to run docker container. I tried downgrading XQuartz but it still didn't fix my issue.
A crucial piece to to the setup is to add your ip access control list for xhost.
xhost + $(ipconfig getifaddr en0)
After adding the ip to xhost, everything works. There is no need to downgrade Xquartz version.

Solution
After installing XQuartz you will need to restart your computer as horcle_buzz suggested; starting a new terminal session is not enough.
After a reboot you can grant access for whatever you need using the xhost command. Just be careful and understand the consequences of too permissive a rule. This other discussion has more info: Running Chromium inside Docker - Gtk: cannot open display: :0
Additional findings
Some extra things I discovered along the way:
XQuartz must be running first:
$ open -a XQuartz
You can expose 127.0.0.1 instead of looking up your local IP (caveat emptor: I'm not an expert on the implications of this setting):
$ xhost + 127.0.0.1
127.0.0.1 being added to access control list
You can use the special host.docker.internal identifier with docker run:
$ docker run -e DISPLAY=host.docker.internal:0 jess/firefox
# 🧙‍♀️ magic 🧙‍♂️
At least for me, ctrl + c does not shutdown the container; I need to close the X11 window manually.
If you quit XQuartz, you must re-auth with xhost after starting it again (the permission doesn't "stick").
Doing it this way I didn't need to mount /tmp/.X11-unix when calling docker run.
I tested this with XQuartz 2.7.11 and Docker Desktop 2.1.0.2 on macOS Mojave (10.14.6).

Related

Lost control over my MariaDB installation

I installed MariaDB on my mac with Macports but lost control over it, mysteriously. I can list the processes and I can login using a user with no privileges. But if I try to stop the database using the usual macports command (sudo port unload mariadb-10.1-server) I get the following error:
/opt/local/etc/LaunchDaemons/org.macports.mariadb-10.1-server/org.macports.mariadb-10.1-server.plist: Could not find specified service
I've tried installing and uninstalling but this doesn't change. How can I do a fresh install of MariaDB on my mac?
Perhaps you inadvertently installed another version of mariadb-server? You can check with:
port echo active |grep mariadb-
It is also possible that the server was started without using launchd and so can't be stopped with the command you were using. You can check with:
sudo launchctl list |grep macports
'org.macports.mariadb-10.1-server' will be in the list if it is running under launchd.
I've deleted the directory where this installation was and reinstalled from Macports. That solved the problem.

Having trouble getting docker to work on mac

OK so here is what I have done so far. I installed docker for mac, and that worked fine. From there I tried to get a project up and running using docker-compose and I got the following error:
Could not read CA certificate "/Users/<useraccountfolder>/.boot2docker/certs/boot2docker-vm/ca.pem": open /Users/<useraccountfolder>/.boot2docker/certs/boot2docker-vm/ca.pem: no such file or directory
So I tried to fix it by trying this accepted answer. This is when I got another error, Host does not exist: “default”. This is when I trie this accepted answer, but when I tried to run docker-machine create default, I got this error: Error with pre-create check: "VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path". I am just lost at this point. Any help?
To use docker machine you need the latest version of VirtualBox, from the docker docs:
IF YOU ARE USING DOCKER FOR MAC
Docker for Mac uses HyperKit, a lightweight macOS virtualization solution built on top of the Hypervisor.framework in macOS 10.10 Yosemite and higher.
Currently, there is no docker-machine create driver for HyperKit, so you will use virtualbox driver to create local machines. (See the Docker Machine driver for Oracle VirtualBox.) Note that you can run both HyperKit and Oracle VirtualBox on the same system. To learn more, see Docker for Mac vs. Docker Toolbox.
Make sure you have the latest VirtualBox correctly installed on your system (either as part of an earlier Toolbox install, or manual install).
Source: https://docs.docker.com/machine/get-started/#prerequisite-information
OK so I found a solution which is probably not fixing the root issue, but it does work. To unset previous variables I ran this command unset ${!DOCKER*}. This worked, but then I had to run it every time I started a new terminal session, so I added it to my .bash_profile and now I am good.

How to run "docker-machine create" in OS X?

I started Docker and am now following the tutorial, but for all I know I couldn't run the docker-machine command on OS X.
The documentation states that you run the following command to create a local virtual machine:
docker-machine create --driver virtualbox manager
However, this command doesn't work in OS X (11.6), with the following error:
Running pre-create checks...
Error with pre-create check: "VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path"
I tried to install the virtualbox; however, another page clearly states that you must not install it on your local machine:
VirtualBox prior to version 4.3.30 must NOT be installed (it is incompatible with Docker for Mac)
Note: If your system does not satisfy these requirements, you can install Docker Toolbox, which uses Oracle VirtualBox instead of HyperKit.
So I only installed Docker for Mac and not virtualbox. So what am I missing here? The example page says you can run the tutorial on OS X, so I wonder how I can proceed...
You can follow along and run this example using Docker for Mac, Docker for Windows or Docker for Linux.
I had the same issue today and resolved it by installing VirtualBox as an additional step after installing Docker for Mac (I did so with brew install --cask virtualbox)
I don't recall having to do the extra install previously, but maybe I already had VirtualBox already installed because of another tool (like Vagrant). Anyway, this is explained in the Docker Machine documentation:
If you are using Docker for Mac
Docker for Mac uses HyperKit, a lightweight macOS virtualization
solution built on top of the Hypervisor.framework in macOS 10.10
Yosemite and higher.
Currently, there is no docker-machine create driver for HyperKit, so
you will use virtualbox driver to create local machines. (See the
Docker Machine driver for Oracle VirtualBox.) Note that you can run
both HyperKit and Oracle VirtualBox on the same system. To learn more,
see Docker for Mac vs. Docker Toolbox.
Make sure you have the latest VirtualBox correctly installed on your system (either as part of an earlier Toolbox install, or manual
install).
I had the same issue. At the same spot ;-)
For me the xhyve driver, available from https://github.com/zchee/docker-machine-driver-xhyve, worked.
In short:
brew install docker-machine-driver-xhyve
You get a notice some links need to be created manually, so copy those and execute
sudo chown root:wheel /usr/local/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve
sudo chown root:wheel /usr/local/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve
Create:
docker-machine create --driver xhyve manager
Without VirtualBox. Im using OS X 10.11.6, too.
After updating my docker docker-machine command stopper working on my mac terminal.
So found after updating my docker I'll have to reinstall docker-machine CLI just to get the latest version.
Updated docker-machine to latest one using the command below helped me making docker-machine command working again.
base=https://github.com/docker/machine/releases/download/v0.16.0 &&
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/usr/local/bin/docker-
machine &&
chmod +x /usr/local/bin/docker-machine
See Docs (https://docs.docker.com/machine/install-machine/#install-machine-directly)

Pycharm docker remote python interpreter

When trying to configure a Remote Python Interpreter in Pycharm using Docker I get the following error:
com.github.dockerjava.api.excepion.DockerClientException: Enabled TLS
verification (DOCKER_TLS_VERIFY=1) but certificate path
(DOCKER_CERT_PATH) '/Users/me/.docker/machine/machines/default'
doesn't exist.
I've $export DOCKER_TLS_VERIFY=0 but with no difference.
I've manually created '/Users/me/.docker/machine/machines/default' but with no joy.
I've deinstalled and reinstalled both Docker and Pycharm but still get the same error.
I'm on a Mac OSX 10.12.1
Pycharm 2016.3
Full disclosure: I use vagrant and virtual box on my mac too.
Any pointers would be appreciated.
Kevin
I fixed it as follows:
Obtain socat (if not already installed)
e.g. brew install socat
Then: socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock
Then in pycharm/docker config:
Api URL: tcp://localhost:2375
Many thanks to the following found on:
https://youtrack.jetbrains.com/issue/IDEA-153973
If you have been using docker-machine for Mac to support PyCharm or the "socat" hack to access Docker API - It is no longer necessary with PyCharm EAP (https://www.jetbrains.com/pycharm/nextversion/) — You can set your remote debugger API_URL directly to: unix:/var/run/docker.sock (supporting debug mode, and the environment runs a lot faster, when not using VirtualBox).
There is a no-questions-asked 30 day trial of EAP before that update goes live (some time this month)

docker-machine:Error with pre-create check: "exit status 126"

When I'm type the code sudo docker-machine create --driver virtualbox default to create a new virtual machine. It can not worked. Here is the info:
xxxMacBook-Pro:~ xxx$ docker --version
Docker version 1.12.0, build 8eab29e
xxxMacBook-Pro:~ xxx$ docker-machine --version
docker-machine version 0.8.0, build b85aac1
xxxMacBook-Pro:~ xxx$ sudo docker-machine create --driver virtualbox default
Running pre-create checks...
Error with pre-create check: "exit status 126"
Please help me to figure this out.
Exit status 126 on a Mac indicates that you don't have Virtualbox installed, which comes separate from Docker.
Run the following command to install it:
brew cask install virtualbox;
Now you can gracefully run your command again.
NB: You don't have to use sudo, unless there are some special privileges you want to accord whatever you are creating.
Update: As of 2021 you can use
brew install --cask virtualbox
The same error occurred on my OSX, because I'v only installed docker.app.
Probably, you should install docker toolbox instead of docker.app.
Docker.app doesn't include virtualbox driver, but docker toolbox includes virtual box driver.
https://www.docker.com/products/docker-toolbox
I had the same problem with Docker for Mac. You need to install VirtualBox additionally from https://www.virtualbox.org/wiki/Downloads

Resources