Docker for MacOS with Homebrew

I haven’t updated the stack build on my Mac for quite some time, as it takes a while. However, I’ve been wanting more recent images for developing on master, and I’d like to be able to stay up to date with the stack without much effort, so when @mwv mentioned some Docker problems in Slack, it triggered an interest in getting that working on my Mac.

I use Homebrew on my Mac, and prefer to use that instead of downloading images from various vendors. So here’s how I installed Docker using Homebrew and used it to run the latest version of the LSST stack:

brew install docker
brew install docker-machine
brew services start docker-machine
brew install virtualbox  # Requires SystemPreferences intervention
docker-machine create default --virtualbox-cpu-count 6 --virtualbox-memory 8192

# Create "docker" group and put me in it
sudo dseditgroup -o create docker
sudo dseditgroup -o edit -a price -t user docker

# Run this to set environment before running docker
eval $(docker-machine env default)

Note:

  • The brew install virtualbox command requires intervention in the “System Preferences” --> “Security & Privacy”: you need to give permission for the installation.
  • The eval $(docker-machine env default) line needs to be run before you use docker run; you may want to put it in your ~/.bashrc.

Once Docker’s installed and set up, you can follow the instructions for using the LSST stack images, e.g.:

docker run -ti -v ~/LSST:/home/lsst/LSST lsstsqre/centos:7-stack-lsst_distrib-w_2018_10
1 Like

An alternative that does require downloading an image from the vendor but does not require brew is to use Docker Community Edition, a single-DMG app install of docker, docker-machine, a menubar widget, etc.

https://download.docker.com/mac/stable/Docker.dmg

1 Like

@price Thanks for posting the clear instructions for going the homebrew route instead of the Docker application DMG image route. Nice to have documentation of different options.

I’ve put the following in my ~/.bashrc and found them helpful:

lsst_latest_weekly () {
    date +'w_%Y_%U'
}

eval "$(docker-machine env default)"

lsstDocker () {
    docker run -ti -v ~/docker:/home/lsst -v ~/LSST:/home/lsst/LSST lsstsqre/centos:7-stack-lsst_distrib-$(lsst_latest_weekly)
}

The result is that when I run lsstDocker, I get the latest weekly LSST-DM Docker, with a persistent home dir and my laptop’s LSST product repos.

Craig Loomis tells me that there’s no need to use a VirtualBox on OSX, but there’s an alternate method.

Without having installed docker, docker-machine or virtualbox (if you did install them, then brew uninstall them), you can do:

brew cask install docker

and it will install “Docker for Mac” in your Applications. Start that up, and then you can use Docker without the constraints of a Virtualbox. (And you can still manage it through brew.)

To get x11 (e.g., for ds9) working, found this useful page. A summary:

  • XQuartz -> Preferences -> Security -> enable “Allow connections from network clients”
  • Quit XQuartz and restart
  • In a terminal, run: xhost + localhost
  • Add to your docker run command-line -e DISPLAY=docker.for.mac.localhost:0.

To use ds9, you’ll also have to download the CentOS 7 binary (put it in a mapped volume), and you’ll need to install the libXft package: docker exec -ti --user=root <CONTAINER_HASH> yum install libXft -y.

1 Like