Docker install issues


#1

I’ve been wrestling with installing Docker through brew. These are the installed formulae:

azure-cli			libyaml
docker				openssl
docker-compose			python
docker-machine			readline
docker-machine-driver-xhyve	screen
fswatch				sqlite
gdbm				telnet
ghostscript			xhyve
jpeg				xz
libtiff

I had a Virtualbox v5 on my machine and then

Luna:~ sysbh$ docker-machine create default --driver xhyve --xhyve-experimental-nfs-share
Creating CA: /Users/sysbh/.docker/machine/certs/ca.pem
Creating client certificate: /Users/sysbh/.docker/machine/certs/cert.pem
Running pre-create checks...
Creating machine...
(default) Image cache directory does not exist, creating it at /Users/sysbh/.docker/machine/cache...
(default) No default Boot2Docker ISO found locally, downloading the latest release...
(default) Latest release for github.com/boot2docker/boot2docker is v18.09.0
(default) Downloading /Users/sysbh/.docker/machine/cache/boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.09.0/boot2docker.iso...
(default) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
(default) Copying /Users/sysbh/.docker/machine/cache/boot2docker.iso to /Users/sysbh/.docker/machine/machines/default/boot2docker.iso...
(default) Creating VM...
Error creating machine: Error in driver during machine creation: exit status 1

I read somewhere I needed Virtualbox v4, but that one I could not get to install.

Then I downloaded and installed Virtualbox v6.0.0 and tried again and I got this:

Luna:~ sysbh$ docker-machine start
Starting "default"...
(default) Waiting for VM to come online...
Machine didn't return an IP after 120 seconds, aborting

Now, I’m at a loss. What do I need to do to get docker from brew running on my macOS High Sierra system?


#2

Hmm, I logged out as the sysadmin user and went back to being a normal user. Then I tried again as that user:

luna-wifi:~ sysbh$ logout
Luna:~ gerben$ docker-machine create default
Creating CA: /Users/gerben/.docker/machine/certs/ca.pem
Creating client certificate: /Users/gerben/.docker/machine/certs/cert.pem
Running pre-create checks...
(default) Image cache directory does not exist, creating it at /Users/gerben/.docker/machine/cache...
(default) No default Boot2Docker ISO found locally, downloading the latest release...
(default) Latest release for github.com/boot2docker/boot2docker is v18.09.0
(default) Downloading /Users/gerben/.docker/machine/cache/boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.09.0/boot2docker.iso...
(default) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Creating machine...
(default) Unable to get the local Boot2Docker ISO version: Did not find prefix "-v" in version string
(default) Default Boot2Docker ISO is out-of-date, downloading the latest release...
(default) Latest release for github.com/boot2docker/boot2docker is v18.09.0
(default) Downloading /Users/gerben/.docker/machine/cache/boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.09.0/boot2docker.iso...
(default) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
(default) Copying /Users/gerben/.docker/machine/cache/boot2docker.iso to /Users/gerben/.docker/machine/machines/default/boot2docker.iso...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Check network to re-create if needed...
(default) Found a new host-only adapter: "vboxnet0"
(default) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env default

Seems to work (with Virtualbox 6.0.0). But why it doesn work when I’m logged in as the sysadmin user that actually is used to manage brew, I’m at a loss. It might be that this is because the GUI is owned by the normal user and Virtualbox somehow requires a connection to that desktop? How am I going to start a docker machine on reboot, then?


(Sean Molenaar) #3

you can use brew services for that. You can read more here: https://github.com/Homebrew/homebrew-services

This is noted in the docker-machine install by the way:

==> Caveats
To have launchd start docker-machine now and restart at login:
  brew services start docker-machine
Or, if you don't want/need a background service you can just run:
  docker-machine start

#4

Documentation talks about ‘at login’’. Are these per-user at login or really root-run at boot services?


(Sean Molenaar) #5

The link I added says how to start something at boot.


#6

Yes, sorry, I misread.

I understand now that if I use sudo brew services it acts on /Library and not on ~/Library and as root.

Interestingly enough, if I run brew services list and sudo brew services list both mention docker-machine (stopped). So, apparently, brew services is a central repository and sudo brew services start or brew services start install the startup in /Library or ~/Library. I hope I understand this correctly.


(Sean Molenaar) #7

Yeah, sounds about right. Actually the central repository is Homebrew itself and a formula can have service information that makes it available to brew services


#8

And then the next hurdle (sorry, I’m trying to follow instructions, but am new to docker and not very well versed in brew). My docker machine is running (started with sudo and will now run at boot). But:

Luna:~ sysbh$ docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See ‘docker run --help’.

Apparently, I have to do some more configuration.


(Sean Molenaar) #9

It seems you still need to add the config to your shell, see step 6 here:

(not really brew support anymore though)


#10

Agree, but there is still something not right with my install I think. Apparently, the default VM is not started at boot. I think because the root user is not aware of it and the LaunchDaemon runs as user root.

bash-3.2# docker-machine start default
Starting "default"...
machine does not exist
bash-3.2# docker-machine create default
Docker machine "default" already exists

#11

Created a new machine as root, then I can get everything working:

bash-3.2# docker-machine ls
NAME           ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
default        -        virtualbox   Error                                         Unknown    machine does not exist
lunaservices   -        virtualbox   Running   tcp://192.168.99.100:2376           v18.09.0   
bash-3.2# docker run busybox echo hello world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
bash-3.2# eval "$(docker-machine env lunaservices)"
bash-3.2# docker run busybox echo hello world
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
57c14dd66db0: Pull complete 
Digest: sha256:7964ad52e396a6e045c39b5a44438424ac52e12e4d5a25d94895f2058cb863a0
Status: Downloaded newer image for busybox:latest
hello world

Still have to test if it survives a reboot, though (changed the LaunchDaemon plist).


#12

OK, there are still some issues. The at-boot launch fails, because the ~/.docker directory used by docker is not ~root/.docker but ~gerben/.docker (where gerben is the user who sudo’d the commands. Hence, in /Users/gerben/.docker/machine/machines we find

drwx------   4 gerben  staff  128 Jan  8 12:09 .
drwx------   5 gerben  staff  160 Jan  7 19:41 ..
drwx------  13 gerben  staff  416 Jan  8 11:45 default
drwx------  13 root    staff  416 Jan  8 12:11 lunaservices

Is there a way to prevent this from happening? Yes, it depends on how you sudo:

Luna:~ gerben$ sudo -i -u root
Password:
Luna:~ root# cd
Luna:~ root# pwd
/var/root
Luna:~ root# logout
Luna:~ gerben$ sudo -s -u root
Password:
bash-3.2# cd
bash-3.2# pwd
/Users/gerben

In other words: it is important to do all the docker commands in a true root login shell if your want the result to be available at boot time from /Library/LaunchDaemons/homebrew.mxcl.docker-machine.plist

Now up to either repairing (moving) or recreating.


(Sean Molenaar) #13

Yeah homebrew and macOS really aren’t made for running things as root. I can’t really help you with that either as it’s not supported by homebrew or something I have experience with. I’ll check back here to see if you have actual homebrew questions though.


#14

Never mind running as root. Running at boot is what I’m primarily after.

I can run docker fine now, except that I haven’t found a way yet to start a docker-machine at boot, so before or without anyone logged in.