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.
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 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
.
-
Stop your docker machine
docker-machine stop stockblocks
-
Remove
docker-machine env
command from.bash_profile
-
Clear docker environment variables
unset ${!DOCKER_*}
-
Download stable channel Docker for mac (https://docs.docker.com/docker-for-mac/) and give the VM 4 GB of memory.
-
Update your hosts file
npm run docker:update-hosts:mac
-
Build your databases
composer install -o && npm run db:build:all
-
Index ElasticSearch
npm run es:index:all:mac
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
If you still have docker variables in your environment, you can unset them to continue on.
unset ${!DOCKER_*}
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.
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.
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
If you get the homepage, congrats! You're almost ready to Rock!
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
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
https://docs.docker.com/docker-for-mac/ https://docs.docker.com/docker-for-mac/docker-toolbox/
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:
or something similar. You could also replace the other shell commands with something like:
Also, this would mean you get to write Node scripts instead of shell scripts, a big win :)