DEV Community

Cover image for The Most Useful Docker Commands for Mac You’ve Never Heard of, Because You Need To Make Them

The Most Useful Docker Commands for Mac You’ve Never Heard of, Because You Need To Make Them

Michael Charles Aubrey on March 01, 2024

The commands are: docker open - Open Docker Desktop (and therefore start the docker daemon) from your terminal. docker close - Close Docker Deskt...
Collapse
 
moopet profile image
Ben Sinclair

I leave docker running all the time and leave my macbook with the lid closed. My workflow is otherwise pretty similar to yours.

I don't think there's any difference between running docker container stop and docker stop, and I can't think of a reason you'd need to attempt to stop containers which aren't running (what the -a gives you), so mine looks like this:

docker stop $(docker ps -q)

I call my version "undock", because I like making it obvious what're official docker commands and what're my additions - I have a very small brain and don't want to get used to expecting subcommands which don't exist on other environments!

Collapse
 
shricodev profile image
Shrijal Acharya

Why just Mac? Shouldn't it work with Linux or WSL? I believe it should.

Collapse
 
michaelcharles profile image
Michael Charles Aubrey

You could make such a script for Linux, but it would need to be altered. The script I posted here is based on opening the Docker Desktop app via the command line. On Linux, you'd probably just want to start or stop the daemon (systemctl start docker and systemctl stop docker). The flush command might work out of the box, especially if you're running Zsh on your Linux machine.

Collapse
 
dmuth profile image
Douglas Muth

This is neat to see. One reason why I got into Orbstack not too long ago was because it comes with a command-line app that lets you start and stop the app like what's shown here.