Docker / Docker Compose 環境構築 with colima, not Docker Desktop
なにもしてないのに Docker Desktop がこわれたので環境構築やり直し
- Docker Desktop の削除
colima を入れてみる
brew install colima
colima start
# INFO[0000] starting colima
# INFO[0000] runtime: docker
# FATA[0000] dependency check failed for docker: docker not found, run 'brew install docker' to install
brew install docker
colima start
# INFO[0000] starting colima
# INFO[0000] runtime: docker
# INFO[0001] creating and starting ... context=vm
# INFO[0002] downloading disk image ... context=vm
# INFO[0027] provisioning ... context=docker
# INFO[0029] starting ... context=docker
# INFO[0029] done
Dockerfile
FROM nginx:stable-alpine3.21-perl
コンテナを起動
docker build -t my-nginx .
# 8080:80 host:container
docker run --name my-nginx-container -d -p 8080:80 my-nginx
# 93950bbfafd43a807657f9e45b738ae833b6c92fafa95b7d3b817837be98fc6c
docker ps
#CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# 93950bbfafd4 my-nginx "/docker-entrypoint.…" 8 seconds ago Up 8 seconds 0.0.0.0:8080->80/tcp, [::]:8080->80/tcp my-nginx-container
ブラウザから http://localhost:8080 にアクセス
いつもの

コンテナの停止
docker ps
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# 93950bbfafd4 my-nginx "/docker-entrypoint.…" 6 minutes ago Up 6 minutes 0.0.0.0:8080->80/tcp, [::]:8080->80/tcp my-nginx-container
docker stop 9395
# 9395
docker ps
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Docker Compose
docker compose コマンドがエラーになる
docker compose コマンドは Docker CLI のプラグインとして入っている。
$HOME/.docker/cli-plugins/docker-compose にプラグインがないと言われている。
docker compose
# docker: unknown command: docker compose
#
# Run 'docker --help' for more information
# ヘルプを見る
docker --help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Common Commands:
run Create and run a new container from an image
exec Execute a command in a running container
ps List containers
...
Invalid Plugins:
buildx failed to fetch metadata: fork/exec /Users/nukopy/.docker/cli-plugins/docker-buildx: no such file or directory
compose failed to fetch metadata: fork/exec /Users/nukopy/.docker/cli-plugins/docker-compose: no such file or directory
Docker Desktop だとインストールするだけで docker compose コマンドが使える。colima はあくまでコンテナランタイムなので、docker のコマンド自体をサポートするものではない。
Starting with Docker Desktop 3.4.0, you can run Compose V2 commands without modifying your invocations, by enabling the drop-in replacement of the previous docker-compose with the new command. See the section Installing Compose for detailed instructions.
解決策があった。
docker-compose コマンドをインストールして、プラグインへのシンボリックリンクを張れば良いみたい。
と思ったけど、公式が提供しているきれいなやり方があるみたい。
brew install docker-compose をインストールしたら以下のようなログが出力された。~/.docker/config.json という設定ファイルに外部プラグイン用のパスが設定できるらしい。
brew install docker-compose
...
==> Caveats
Compose is a Docker plugin. For Docker to find the plugin, add "cliPluginsExtraDirs" to ~/.docker/config.json:
"cliPluginsExtraDirs": [
"/opt/homebrew/lib/docker/cli-plugins"
]
==> Summary
🍺 /opt/homebrew/Cellar/docker-compose/2.38.2: 8 files, 60.7MB
...
~/.docker/config.json を修正:
cat ~/.docker/config.json
{
"auths": {
"905418409993.dkr.ecr.ap-northeast-1.amazonaws.com": {},
"https://index.docker.io/v1/": {}
},
"credsStore": "desktop",
"currentContext": "colima",
"plugins": {
"debug": {
"hooks": "exec"
},
"scout": {
"hooks": "pull,buildx build"
}
},
"features": {
"hooks": "true"
- }
+ },
+ "cliPluginsExtraDirs": [
+ "/opt/homebrew/lib/docker/cli-plugins"
+ ]
}
(colima の再起動は不要だった)再度 docker --help を実行してみると、Invalid Plugins から compose が消え、Management Commands に compose* が追加されている(* は外部プラグインの意味かな?)。
docker --help
# Usage: docker [OPTIONS] COMMAND
#
# A self-sufficient runtime for containers
#
# Common Commands:
# run Create and run a new container from an image
# exec Execute a command in a running container
# ps List containers
# ...
# Management Commands:
# builder Manage builds
# compose* Docker Compose <----- `compose` command appears!
# ...
# Invalid Plugins:
# buildx failed to fetch metadata: fork/exec /Users/nukopy/.docker/cli-plugins/docker-buildx: no such file or directory
# `compose` command disappears!
# debug failed to fetch metadata: fork/exec /Users/nukopy/.docker/cli-plugins/docker-debug: no such file or directory
...
docker compose コマンドを実行すると usage がちゃんと表示される:
docker compose
# Usage: docker compose [OPTIONS] COMMAND
#
# Define and run multi-container applications with Docker
# ...
というこれまでの過程を指摘してくれている issue コメントがありました (終わった後に気づいた)
「Homebrew の出力が変わっているからこっち(↑で自分がやってきたやり方)でできるよ!」という旨のコメント。
準備ができたので以下の compose.yml を実行してみたがエラーが発生。
docker compose up
# [+] Running 0/3
# ⠋ busybox Pulling 0.0s
# ⠋ db Pulling 0.0s
# ⠋ redis Pulling 0.0s
# error getting credentials - err: exec: "docker-credential-desktop": executable file not found in $PATH, out: ``
`compose.yml`(今回は中身は何でも良い)
services:
busybox:
container_name: my-busybox-container
image: busybox:latest
command: ["sh", "-c", "exec while true; do echo hello world; sleep 1; done"]
restart: always
networks:
- my-custom-network
nginx:
container_name: my-dc-nginx-container
build: .
ports:
- "8080:80"
networks:
- my-custom-network
db:
container_name: my-db-container
image: postgres:latest
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: mydb
volumes:
- db_data:/var/lib/postgresql/data
networks:
- my-custom-network
redis:
container_name: my-redis-container
image: redis:latest
ports:
- "6379:6379"
volumes:
- redis_data:/data
networks:
- my-custom-network
volumes:
db_data:
redis_data:
networks:
my-custom-network:
name: my-custom-network
o3 に聞いてみたら答えが出た。クレデンシャル情報の格納場所(credsStore)が Docker Desktop のままだったみたい。
Docker CLI はイメージを pull するときに「どのレジストリに、どんな資格情報でアクセスするか」を
~/.docker/config.jsonに書かれた “credential helper” に丸投げします。あなたのconfig.jsonにはn"credsStore": "desktop"または
"credHelpers": { "docker.io": "desktop" }のような行が残っていて、CLI は
docker‑credential‑desktopという実行ファイルを呼びに行きます。
ところが Docker Desktop をアンインストール/使わなくした(colima だけにした) ことで、その実行ファイルが PATH 上から消えたためexec: "docker‑credential‑desktop": executable file not found in $PATHというエラーになっています。
修正する:
{
"auths": {
"905418409993.dkr.ecr.ap-northeast-1.amazonaws.com": {},
"https://index.docker.io/v1/": {}
},
- "credsStore": "desktop",
"currentContext": "colima",
"plugins": {
"debug": {
"hooks": "exec"
},
"scout": {
"hooks": "pull,buildx build"
}
},
"features": {
"hooks": "true"
},
"cliPluginsExtraDirs": [
"/opt/homebrew/lib/docker/cli-plugins"
]
}
詳細
原因
Docker CLI はイメージを pull するときに「どのレジストリに、どんな資格情報でアクセスするか」を ~/.docker/config.json に書かれた “credential helper” に丸投げします。あなたの config.json には
"credsStore": "desktop"
または
"credHelpers": {
"docker.io": "desktop"
}
のような行が残っていて、CLI は docker‑credential‑desktop という実行ファイルを呼びに行きます。
ところが Docker Desktop をアンインストール/使わなくした(colima だけにした) ことで、その実行ファイルが PATH 上から消えたため
exec: "docker‑credential‑desktop": executable file not found in $PATH
というエラーになっています。
直し方 3 通り
| やりたいこと | 手順 |
|---|---|
| 一番シンプル:設定を消す | 1. nano ~/.docker/config.json(好きなエディタでOK)2. "credsStore": "desktop" 行、または "desktop" と書かれた credHelpers の行を削除3. 保存して docker compose up を再実行 |
| macOS で Keychain を使う | 1. brew install docker-credential-helper などで docker‑credential‑osxkeychain が入っている前提で2. config.json の "credsStore": "desktop" を "osxkeychain" に書き換え |
| どうしても設定をいじりたくない |
ln -s $(which docker-credential-osxkeychain) /usr/local/bin/docker-credential-desktop※ 代替バイナリを偽装して置くだけ |
修正後、必要なら docker login で再ログインしてください。
補足:credential helper とは
- Docker CLI が「レジストリ用のパスワードを安全に保存/取得する」ための外部プログラム。
- macOS の Docker Desktop には専用の
docker-credential-desktopが同梱されており、Keychain 経由でトークンを管理。 - Homebrew 版 Docker などでは
docker-credential-osxkeychain(または Linux ならdocker-credential-passなど)を使う。
Docker Desktop をやめて colima などに移行したときは、config.json の helper 指定を書き換えるか消すのを忘れずに 👍
再度 docker compose up。またエラー。
docker-buildx プラグインがないらしい。
Compose V2 系(docker compose コマンド)はイメージをビルドするときに BuildKit + buildx を使う。
➜ docker compose up
[+] Running 24/24
✔ busybox Pulled 7.7s
✔ 189fdd150837 Pull complete 4.6s
✔ db Pulled 10.3s
✔ 37259e733066 Pull complete 2.3s
✔ ad9bf12774e0 Pull complete 2.3s
✔ 6c7475e9a1eb Pull complete 2.4s
✔ fd3187d6acde Pull complete 2.5s
✔ 573b5990cac7 Pull complete 2.7s
✔ 34ed8d648854 Pull complete 2.7s
✔ e0da14ecf374 Pull complete 2.7s
✔ a3e06971819c Pull complete 2.7s
✔ 8b584fe980c8 Pull complete 7.2s
✔ 7e8924348af8 Pull complete 7.2s
✔ 62d6ecd3917a Pull complete 7.2s
✔ 47d365097430 Pull complete 7.2s
✔ 183c1a68f8aa Pull complete 7.2s
✔ 7683a1632945 Pull complete 7.2s
✔ redis Pulled 9.5s
✔ 6724eb393acd Pull complete 4.8s
✔ 746d6e37cd6e Pull complete 5.0s
✔ fcd9a200a986 Pull complete 6.4s
✔ e19c7e9db449 Pull complete 6.4s
✔ 4f4fb700ef54 Pull complete 6.4s
✔ 3b5fad749431 Pull complete 6.5s
fork/exec /Users/nukopy/.docker/cli-plugins/docker-buildx: no such file or directory
docker build だと大丈夫なのは以下の理由:
- なぜ今になって出た?
- docker build 単体だと 古いクラシックビルダー がフォールバックで動くので、buildx が無くてもこけない。
- Compose は 2024 年以降、明示的に buildx を要求する仕様になった。
- → CLI プラグインが入っていない Homebrew‑版 Docker + colima 環境 だとこうなる。
buildx プラグインのインストール。
compose プラグインを入れたときと同様の外部プラグイン用のパスの設定方法が表示されるが、先程 compose の方でやったので不要。
brew install docker-buildx
# ==> Caveats
# docker-buildx is a Docker plugin. For Docker to find the plugin, add "cliPluginsExtraDirs" to ~/.docker/config.json:
# "cliPluginsExtraDirs": [
# "/opt/homebrew/lib/docker/cli-plugins"
# ]
再度 docker compose up。できた!
