Skip to content
Jonas Chevalier edited this page Mar 20, 2022 · 2 revisions

When using Docker Machine on OS X, there's an incantation that needs to be run in every shell where you want to run Docker. Direnv can help mitigate that annoyance:

Add to ~/.config/direnv/direnvrc

use_docker-machine(){
  local env=${1:-default}
  echo Docker machine: $env
  local machine_cmd=$(docker-machine env --shell bash $env)

  eval $(docker-machine env --shell bash $env)
}

Any project that's using docker, add to .envrc:

use docker-machine

One nice feature to this is that you can have different Docker machine VMs per project, if needed by saying use docker-machine special, for instance.

Note that when using this pattern, when docker-machine warns you to eval (docker-machine env), you'll want instead to direnv reload.

Clone this wiki locally