Skip to content

Instantly share code, notes, and snippets.

@grocky
Last active March 26, 2018 14:26
Show Gist options
  • Save grocky/733138db1bf8bf8f53bf1de9feab4454 to your computer and use it in GitHub Desktop.
Save grocky/733138db1bf8bf8f53bf1de9feab4454 to your computer and use it in GitHub Desktop.
migrating from docker toolbox to docker for mac

Overview

Docker for Mac is the next step toward bringing native Docker to OSX. We've built some tooling around boot2docker and docker-machine that now is no longer needed! This guide will help you migrate from the Docker toolbox to Docker for Mac.

Docker toolbox

docker toolbox image

The docker toolbox provides a virtual machine that runs the docker engine and allows a local docker client to interact with the docker ecosystem (images, containers, etc.).

Docker for mac

docker for mac image

Docker for mac uses the hypervisor virtualization layer included with OSX that allows the docker engine to run locally very similarly to how it's run on Linux. This means that the "public" ip addresses for containers will be your localhost.

Set up steps

TL;DR

  1. Stop your docker machine

    docker-machine stop stockblocks
  2. Remove docker-machine env command from .bash_profile

  3. Clear docker environment variables

    unset ${!DOCKER_*}
  4. Download stable channel Docker for mac (https://docs.docker.com/docker-for-mac/) and give the VM 4 GB of memory.

  5. Update your hosts file

    npm run docker:update-hosts:mac
  6. Build your databases

    composer install -o && npm run db:build:all
  7. Index ElasticSearch

    npm run es:index:all:mac

Cleanup

First, let's shut down your docker-machine

docker-machine stop stockblocks

Then, we need to cleanup environment variables that override the docker client configuration. Typically, we've added a command in your .bash_profile or .bashrc (or whichever startup script your shell uses). Look for a line like this in one of those files:

eval "$(docker-machine env stockblocks 2>/dev/null)"

Start up a new shell (or reload it) and verify that your environment does not have any docker variables.

env | grep DOCKER

Only if necessary cleanup

If you still have docker variables in your environment, you can unset them to continue on.

bash only

unset ${!DOCKER_*}

other shells

unset DOCKER_HOST
unset DOCKER_FOO

You can find rogue docker variable exports by adding set -x to your .bash_profile which can help determine when a variable was exported which will lead you to the overstepping file.

Installation

Docker.app

Head over to docker https://docs.docker.com/docker-for-mac/ to download and install Docker.app from the Stable Channel.

Once installed, go ahead and up the memory to 4GB. This seems to be working well for now, but we may need to revisit it later.

screen shot 2016-08-11 at 5 52 24 pm

docker preferences

StockBlocks

First, let's setup our hosts file to point our stockblocks.local addresses to localhost

npm run docker:update-hosts:mac

Then spin up the containers

docker-compose up -d

NOTE: This will download the world our first time; grab some coffee

Once everything is up create your db and open up videoblocks

composer install -o && npm run db:build:all
open http://videoblocks.local

vb homepage image

If you get the homepage, congrats! You're almost ready to Rock!

ElasticSearch

The last step is to index ElasticSearch. To limit the amount of memory needed for the VM, we need to create indexes individually. Run these commands and you'll be good to go

npm run es:index:all:mac

XDebug

NOTE: in StockBlocks you can run ./scripts/docker/setup-xdebug.sh instead

This is a work around setup because the docker-for-mac network is different. We're currently working on a better way to set this up, but for now:

  • Create an alias for your mac loopback interface

    sudo ifconfig lo0 alias 10.254.254.254
  • In the webhead container, open /etc/php/7.0/fpm/conf.d/40-custom-dev.ini and add these configurations

    • xdebug.remote_host=10.254.254.254 in the web head cont
    • xdebug.remote_connect_back = 0
  • Restart web container

    docker-compose restart web

Resources

https://docs.docker.com/docker-for-mac/ https://docs.docker.com/docker-for-mac/docker-toolbox/

@jonathan-fulton
Copy link

jonathan-fulton commented Aug 5, 2016

This is awesome! Random suggestion: we might want to consider using npm as a task runner even in StockBlocks. For instance even in our Python project, I use it to run node scripts to build, deploy, and do a few other things. For instance, setting up ElasticSearch could be as simple as:

npm run es:index:all

or something similar. You could also replace the other shell commands with something like:

npm run db:build:all

Also, this would mean you get to write Node scripts instead of shell scripts, a big win :)

@grocky
Copy link
Author

grocky commented Aug 11, 2016

Just saw your comment. I've since updated the gist with the npm commands instead.

@aarsilv
Copy link

aarsilv commented Aug 18, 2016

Since some migrations may require composer's autoloading, we should add in before the call to npm run db:build:all to do a composer install just in case!

@grocky
Copy link
Author

grocky commented Aug 18, 2016

Done!

@jasonvideoblocks
Copy link

Let's also add a note about needing to restart after making the changes on the web container. (Assuming that is necessary, but it didn't work for me until I did.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment