Post

How to use Docker without Docker Desktop on MacOS (M2)

If you are facing challenges with Docker Desktop licensing for a large software team, this guide will assist you in easily utilizing Docker CLI on Mac machines with M2 chips.

Licensing only affect the Docker Desktop product, the CLI interface remains free for all users.

Prerequisite

Setup Docker without Docker Desktop manually

1. Install Docker and the docker-credential-helper. The credential helper allows you to use the macOS Keychain as the credential store for remote container repos instead of Docker Desktop.

1
brew install docker docker-credential-helper
  • You may encounter an issue later on where the Docker CLI throws an error stating that ‘docker-credential-desktop’ is not installed. This error is likely caused by a misconfiguration, possibly from a previous installation of Docker Desktop. You can resolve this issue by following these steps.
1
2
3
4
5
6
7
nano ~/.docker/config.json

{
        "auths": {},
        "credsStore": "osxkeychain",
        "currentContext": "colima"
}

2. Colima is a container runtime that supports Docker (and containerd) and needs to be installed.

1
brew install colima

3. After installing, simply initiate the Colima VM to start using it.

1
2
colima start
docker context use colima

4. Test the setup

1
docker run hello-world

Installation script

If you are looking for a quick and easy method to set up the Docker CLI, use this script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash

SHELL_TYPE="$(basename "$SHELL")"

brew update && brew install docker docker-credential-helper colima

cat <<EOF > ~/.docker/config.json
{
        "auths": {},
        "credsStore": "osxkeychain",
        "currentContext": "colima"
}
EOF

colima start
docker context use colima

if [ "$SHELL_TYPE" = "bash" ]; then
    echo "alias docker-start='colima start'" >> ~/.bashrc
    echo "alias docker-stop='colima stop'" >> ~/.bashrc
    source ~/.bashrc
elif [ "$SHELL_TYPE" = "zsh" ]; then
    echo "alias docker-start='colima start'" >> ~/.zshrc
    echo "alias docker-stop='colima stop'" >> ~/.zshrc
    source ~/.zshrc
else
    echo "Unsupported shell: $SHELL_TYPE"
fi

  • How to start or stop Docker runtime
1
2
docker-start
docker-stop

Control Docker

If you’re not comfortable with the Docker CLI, you can use the Docker extension in VSCode to easily manage containers, images, volumes, and networks.

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.