96

Docker for Mac has a neat little 'restart' button in the dropdown from the whale icon in the menu bar.

I'd like to be able to restart Docker for Mac from the terminal, though. What command would I need to run?

5 Answers 5

138

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.

5
  • 14
    Nice. Here's the alias I've added to my bash profile: alias docker_restart="osascript -e 'quit app \"Docker\"' && open -a Docker"
    – rouan
    Mar 6, 2018 at 13:55
  • osascript? I don't have that command.
    – skittlebiz
    Dec 14, 2022 at 1:38
  • That was surprisingly simple. Thanks! Jan 16 at 14:00
  • 1
    open -a Docker that's nice ;)
    – Jono
    Feb 24 at 13:45
  • 1
    Looks to me that on MacOS 12.5, M1 Mac osascript -e 'quit app "Docker"' does a restart
    – Jono
    Feb 24 at 13:48
42

The following command worked for me:

killall Docker && open /Applications/Docker.app
0
21

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 ""
12

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

1

This is what I am using (source):

alias docker_restart="curl -X POST -H 'Content-Type: application/json' -d '{ \"openContainerView\": true }' -kiv --unix-socket ~/Library/Containers/com.docker.docker/Data/backend.sock http://localhost/engine/restart"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.