Machine: docker-machine env is slow

Created on 19 Sep 2015  路  5Comments  路  Source: docker/machine

I could not find an open ticket regarding this problem, but I guess I'm not the only one having this problem?

$ uname -a
Darwin 14.5.0 Darwin 
Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; 
root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
$ time docker-machine env dev >/dev/null

real    0m0.254s
user    0m0.217s

.. so having eval $(docker-machine env dev) in .bash_profile is no fun.

Workaround 1: Hard code the exports

$ docker-machine env dev >> ~/.bash_profile

Workaround 2: Very dirty lazy-loading fix

# Lazy load docker-machine env on first docker run
alias docker='docker-machine start dev>/dev/null && eval $(docker-machine env dev) && unalias docker && docker'

Most helpful comment

I ended up with this, it runs in 0.040 for me.

: ${DOCKER_MACHINE_NAME="my_vm_name"}

docker-machine inspect ${DOCKER_MACHINE_NAME} --format \
"export DOCKER_HOST=tcp://{{ .Driver.IPAddress }}:2376
export DOCKER_TLS_VERIFY=1
export DOCKER_CERT_PATH={{ .HostOptions.AuthOptions.StorePath }}
export DOCKER_MACHINE_NAME=${DOCKER_MACHINE_NAME}"

All 5 comments

It's harder than it looks to make it fast, since you have to actually lookup the IP address of the VM in question (and regenerate certs if they have been invalidated). If you're willing to accept the consistency tradeoff, you might be able to make your own version using the values "cached" by inspect, but I can't guarantee that will work forever.

I'm going to close this as I can't think of a way to improve the current method without sacrificing consistency, but feel free to open a new issue with suggestions on how the method might be improved, e.g. docker-machine env --cached dev to use "cached" values.

I'm not that familiar with docker-machine, so it's hard to come up with a suggestion. I just wanted to report the issue so it could be discussed :)

I'm using the vmwarefusion driver btw.

Thanks for reporting, and noted!

I ended up with this, it runs in 0.040 for me.

: ${DOCKER_MACHINE_NAME="my_vm_name"}

docker-machine inspect ${DOCKER_MACHINE_NAME} --format \
"export DOCKER_HOST=tcp://{{ .Driver.IPAddress }}:2376
export DOCKER_TLS_VERIFY=1
export DOCKER_CERT_PATH={{ .HostOptions.AuthOptions.StorePath }}
export DOCKER_MACHINE_NAME=${DOCKER_MACHINE_NAME}"
Was this page helpful?
0 / 5 - 0 ratings