Restart Docker from command line

What’s the correct way to restart Docker for the Docker for Mac beta from the command line?

4 Likes

There isn’t a supported way to do this from the command line right now. The best way is to Quit and Re-Open Docker for Mac. There is a pinata restart command but it’s for troubleshooting only and will likely disappear in a future beta.

Thanks for trying out Docker for Mac!

Thanks for the feedback. Good to know about the pinata restart command for the interim. I hope consideration is given to providing official support to start/stop/restart from the command line.

2 Likes

Would also love some official ways to start/stop the service. I was going to update https://github.com/matryer/bitbar-plugins/blob/e3ebf9ec6f941d29646dff9fe0c6bc6af8f57a56/Dev/Docker/docker-status.1m.sh (Bitbar plugin to show containers for docker) but I don’t see official ways documented anywhere.

I found “launchctl start com.docker.helper” to start the service and I’m sure I can find other ways to do it by debugging the process but it would be nice if this was officially documented somewhere.

1 Like

I’ve found that a simple

killall com.docker.osx.hyperkit.linux

will do the trick on macOS.

1 Like

Kill the app and reopen it. Is the same of restart

killall Docker && open /Applications/Docker.app
7 Likes

How to control Docker for Mac from the CLI

Stop Docker for Mac gracefully

test -z "$(docker ps -q 2>/dev/null)" && osascript -e 'quit app "Docker"'

Note: Requires all Docker containers in the stopped state


Stop all Docker containers without confirmation (dangerous if running something)

docker ps -q | xargs -L1 docker stop

Note: Assumes all running Docker containers are in a quiesced state


Start Docker gracefully

open --background -a Docker

Note: It may take up to a minute for Docker to fully start

5 Likes

Note: It may take up to a minute for Docker to fully start

I used the following snippet to deal with the issue of knowing when docker is ready to take commands:

while ! docker system info > /dev/null 2>&1; do sleep 1; done

So e.g.:

open --background -a Docker &&
  while ! docker system info > /dev/null 2>&1; do sleep 1; done &&
  docker run busybox
3 Likes

That won’t work on a machine which hasn’t logged into the Mac GUI:

LSOpenURLsWithRole() failed for the application /Applications/Docker.app with error -610.

launchctl show docker server, remand docker server name

launchctl list | grep docker

111117   0       com.docker.docker.2388

then stop and start it

launchctl stop com.docker.docker.2388 && launchctl start com.docker.docker.2388

Were you using iTerm2 when you got that error? - I recall getting pretty much the same error shortly after bootstrapping a new Mac on Mojave, and attempting to launch a dashboard from the command-line in iTerm2 ( error -600 in my case…). When a simple test with open http://github.comthrew exactly the same error, but then worked fine in the Terminal app, it was a pretty short trip to Security & Privacy --> Privacy --> adding iTerm2 to “Full Disk Access”, and resolution. Anyway, as mentioned by others in this thread, while it’s more pull than push, using the built-in Terminal app to curl the Github API, and scripts that perhaps leverage some combination of sudo -v/sudo -n, osascript -e and establishing some gating with a few while loops conditioned onsleep 1;, etc. seem like pretty good ideas :slight_smile:

Is there any update to start docker for mac like a daemon on boot without user login ?

1 Like

Thanks, this worked for me!

This works fine for Pro CML docker start.

FYI, on Apple Silicon, the GUI does this:

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
3 Likes

I am looking for the very same thing.

There has to be a way to start a daemon without requiring any GUI.

Please - anyone from docker over here?

Just trying to standardize operational procedures all across (ubuntu/debian, redhat/centos, windows & macos…).

THANKS!

Docker Desktop is more than just a daemon. The Docker daemon itself runs in a virtual machine and not even directly in the virtual machine but in a containerd container. I actually entered that container in my presentation at Docker Community All-Hands #6. You can find a blogpost based on that with the link to the video here:

Docker Desktop was meant to be a developer tool and not a server that we control from the terminal except that we can obviously use the Docker client from the host but that connects to the remote daemom inside the virtual machine.

As you, I like to use the terminal too and control things from scripts sometimes. but I have never needed it for Docker Desktop. If you feel you need it, you can ask for it in the roadmap. I don’t think there is an easy way today.

Docker, Inc tries to give us a unified way to use Docker Desktop, but every operating system is different so there have to be differences. I think it is hard enough to maintain it and keep it stable on each platform so it could be one of the reasons why we don’t have a way to control the virtual machines from terminal yet. Even if we had a way, Docker Desktoo would still be different, since that feature would most likely not be implemented in the docker client, but as a separate cli application. If you use only Docker Desktop, that could work, but there are some features that you can’t use with Docker Desktop. And we are back to the beginning that Docker Desktop was created to be a Developer tool and the fact that it uses virtual machines (it has to) makes it unsuitable for some tasks.

I hope I could clear some things up, but feel free to share your ideas in the roadmap :slight_smile: .

Hi everyone,

I do get it that the Docker Desktop is more than an engine - but I do not believe I need the “more” (personally). Hence my question.

Could it be possible to start the daemon each time I start my Mac without having to start the whole desktop application?

THANKS!

There is an option in the General preferences

Screenshot 2022-12-20 at 0.56.44

“Open Docker Dashboard at startup”

You can disable it so the virtual machine with the Docker Daemon inside would start but not the graphical interface.

To be honest, I haven’t tried that since my desktop doesn’t start automatically at all. So I guess the dashboard will not pop up, but the icon at the top of the screen would be still there so you can stop the desktop when you don’t need it.

Would love this functionality.

Any version higher than 4.12 hangs when launched. This issue was avoided by disabling auto-update on the Docker client. Now I just started stumbling into a memory leak on 4.12, and am testing different solutions (e.g. restarting the Docker client when memory usage exceeds $x). This issue is observed on a MacBook Pro w/ Intel chipset (tested with macOS Monterey & Ventura).