Skip to content

command line – How to launch docker container from CLI in MacOS (eg `docker run …`)?

  • by
Spread the love

As far as I know, Docker cannot be installed on a headless machine.

I finally gave-up and had someone plug a damn monitor into the Mac Mini in the datacenter. When they did, they saw a window that said

“Docker” is an app downloaded from the internet. Are you sure you want to open it?

Homebrew Cask downloaded this file on 3 May 2022 from Aplle checked it for malicious software and none was detected.

It’s super annoying that no output was given by Apple on the CLI to indicate this, but whatever.

I figured, for future reference, I’d bypass this using the CLI. You can do so as follows:

xattr -r -d /Applications/

I ran sudo open /Applications/ again. This time it exited 1 with an error message

LSOpenURLsWithRole() failed with error -600 for the file /Applications/

This is where I gave-up on the CLI. In the GUI was a window that said:

Docker desktop needs privileged access.

Docker Desktop needs privileged access to install its networking components and links to the Docker apps.

You will be asked for your password.

I just clicked “OK” and typed my password into the GUI.

After I did that, the docker binary was available

user@host ~ % ls /usr/local/bin/docker
user@host ~ %

user@host ~ % export DOCKER_CONTENT_TRUST=1

user@host ~ % docker run --rm -it --entrypoint /bin/bash debian:stable-slim 
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
user@host ~ % 

The above error was resolved by ticking “I accept the terms” and clicking Accept in a silly ToS that also appears to be only available to the GUI :facepalm:

After that, I re-opened Docker again

open -a Docker

Again, it exited immediately and no bloody output was printed on the terminal. But in the GUI a window opened that said Docker was starting. After half a minute or so, I could finally start a damn container

user@host ~ % docker run --rm -it --entrypoint /bin/bash debian:stable-slim
Unable to find image 'debian:stable-slim' locally Pulling from library/debian
2bc8f4ca4fd1: Pull complete 
Digest: sha256:3d412a8a2e0f087738e6185c5cddab08827880a23e5bd9dc8b2494d89e4b33fd
Status: Downloaded newer image for debian@sha256:3d412a8a2e0f087738e6185c5cddab08827880a23e5bd9dc8b2494d89e4b33fd
Tagging debian@sha256:3d412a8a2e0f087738e6185c5cddab08827880a23e5bd9dc8b2494d89e4b33fd as debian:stable-slim

Leave a Reply

Your email address will not be published. Required fields are marked *