如何从终端重新启动 Mac 的 Docker?

Docker for Mac 在菜单栏鲸鱼图标的下拉列表中有一个简洁的“重启”按钮。

不过我希望能够从终端为 Mac 重启 Docker。我需要运行什么命令?

67965 次浏览

Looks like there is no way to perform this.

I found an official answer for the same question in:

https://forums.docker.com/t/restart-docker-from-command-line/9420/2

Hope they include this feature soon.

Regards

Specifically for Docker for Mac, because it's a "GUI" app, there's a workaround:

osascript -e 'quit app "Docker"'

Since you'd want to restart, here's the way to open it from the command line:

open -a Docker

There's probably a more symmetrical command to open using osascript, but the open command seems more common than the osascript one.

Docker takes a while to initialize.

osascript -e 'quit app "Docker"'; open -a Docker ; while [ -z "$(docker info 2> /dev/null )" ]; do printf "."; sleep 1; done; echo ""

The following command worked for me:

killall Docker && open /Applications/Docker.app