Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect if docker for mac is installed?

I have some makefiles where most of the stuff should run without configuration. These makefiles have used docker-machine in the past.

Is there a way to detect in bash if the user is using docker desktop for mac instead of docker-machine ?

like image 974
JE42 Avatar asked Jul 06 '16 12:07

JE42


2 Answers

The cleanest way I found so far is:

[[ $(docker version --format "{{.Server.KernelVersion}}") == *-moby ]]
like image 74
nikolay Avatar answered Sep 21 '22 13:09

nikolay


The best way is to check for the existence of the DOCKER environment variables:

  • DOCKER_HOST
  • DOCKER_MACHINE_NAME
  • DOCKER_TLS_VERIFY
  • DOCKER_CERT_PATH

All four of these are set when eval $(docker-machine env) is run and are required for use with docker-machine.

The beta does not require any of them being set and in fact requires you to unset them in order to function properly.


You can also do a check in the docker info command looking for "moby" (the name of the docker for mac VM):

docker info | grep -q moby && echo "Docker for mac beta" || echo "Not docker for mac beta"

This is going to be dependent on consistency in the docker info results, however.

like image 36
enderland Avatar answered Sep 21 '22 13:09

enderland