简体   繁体   中英

Ensure docker daemon is running on the host in script file

A Mac OSX runs a bash script where the docker command is used and often gives the error:

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Then I do Cmd+Space to open the Spotlight Search and type docker terminal in order to fire up the docker terminal so that the shell script does not fail

Is there a way to do this in the script so that it runs the docker daemon every time it runs?
I tried the following for no avail.

docker-machine start default

I am running Docker version 1.12.0, build 8eab29e

You can put this command in your script:

[[ $(docker-machine status) == "Stopped" ]] && docker-machine start
eval $(docker-machine env)

This will start docker-machine if it is sopped and populate your current environment with docker machine related variables.

If docker-machine is already running then this script will just set environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM