Closed21
MacBook に Docker をインストールした際の備忘録
Docker CLI のインストール
brew install docker
- Docker CLI のインストールのみ
- Docker daemon のインストールはないためこの段階ではまだ Docker を使用はできない
ダウンロード時のログを以下に残しておく。
log
==> Downloading https://formulae.brew.sh/api/formula.jws.json
==> Downloading https://formulae.brew.sh/api/cask.jws.json
Warning: Treating docker as a formula. For the cask, use homebrew/cask/docker or specify the `--cask` flag. To silence this message, use the `--formula` flag.
==> Downloading https://ghcr.io/v2/homebrew/core/docker/manifests/28.0.1
####################################################################################### 100.0%
==> Fetching dependencies for docker: docker-completion
==> Downloading https://ghcr.io/v2/homebrew/core/docker-completion/manifests/28.0.1
####################################################################################### 100.0%
==> Fetching docker-completion
==> Downloading https://ghcr.io/v2/homebrew/core/docker-completion/blobs/sha256:53df5954eda05c
####################################################################################### 100.0%
==> Fetching docker
==> Downloading https://ghcr.io/v2/homebrew/core/docker/blobs/sha256:ce6746f4260d1af97c4a0cc96
####################################################################################### 100.0%
==> Installing dependencies for docker: docker-completion
==> Installing docker dependency: docker-completion
==> Downloading https://ghcr.io/v2/homebrew/core/docker-completion/manifests/28.0.1
Already downloaded: /Users/{user name}/Library/Caches/Homebrew/downloads/35d7823677117ca433504eef63bbdffd8d8a8fe5520e3b79452b0362980f979e--docker-completion-28.0.1.bottle_manifest.json
==> Pouring docker-completion--28.0.1.all.bottle.tar.gz
🍺 /opt/homebrew/Cellar/docker-completion/28.0.1: 10 files, 341.8KB
==> Installing docker
==> Pouring docker--28.0.1.arm64_sequoia.bottle.tar.gz
🍺 /opt/homebrew/Cellar/docker/28.0.1: 13 files, 26.8MB
==> Running `brew cleanup docker`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
またこの段階で Docker CLI のバージョン確認が可能となる。
docker --version
# Docker version 28.0.1, build 068a01ea94
Lima のインストール
brew install lima
Mac のローカル環境に Linux 仮想マシンを作成・管理するためのツール。
log
==> Downloading https://ghcr.io/v2/homebrew/core/lima/manifests/1.0.6
####################################################################################### 100.0%
==> Fetching lima
==> Downloading https://ghcr.io/v2/homebrew/core/lima/blobs/sha256:dd5d16c2ed7eb78905faa12dbf1
####################################################################################### 100.0%
==> Pouring lima--1.0.6.arm64_sequoia.bottle.tar.gz
==> Caveats
zsh completions have been installed to:
/opt/homebrew/share/zsh/site-functions
==> Summary
🍺 /opt/homebrew/Cellar/lima/1.0.6: 107 files, 209.7MB
==> Running `brew cleanup lima`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
ima --version
# limactl version 1.0.6
Docker デーモンのセットアップ
limactl start --name=default template://docker
途中選択肢が出てくるが「Proceed with the current configuration」を選択する。(矢印キーで移動し Enter を押す)
log
? Creating an instance "default" Proceed with the current configuration
INFO[0111] Starting the instance "default" with VM driver "vz"
INFO[0111] Attempting to download the image arch=aarch64 digest="sha256:f11282a728ad42f8bfe0b646a6807674d79a019bfc229d80032345dd3228a2db" location="https://cloud-images.ubuntu.com/releases/24.04/release-20250115/ubuntu-24.04-server-cloudimg-arm64.img"
Downloading the image (ubuntu-24.04-server-cloudimg-arm64.img)
574.07 MiB / 574.07 MiB [-----------------------------------] 100.00% 6.10 MiB/s
INFO[0207] Downloaded the image from "https://cloud-images.ubuntu.com/releases/24.04/release-20250115/ubuntu-24.04-server-cloudimg-arm64.img"
INFO[0207] Converting "/Users/{user name}/.lima/default/basedisk" (qcow2) to a raw disk "/Users/{user name}/.lima/default/diffdisk"
3.50 GiB / 3.50 GiB [---------------------------------------] 100.00% 1.37 GiB/s
INFO[0210] Expanding to 100GiB
INFO[0210] [hostagent] hostagent socket created at /Users/{user name}/.lima/default/ha.sock
INFO[0210] [hostagent] Starting VZ (hint: to watch the boot progress, see "/Users/{user name}/.lima/default/serial*.log")
INFO[0211] SSH Local Port: 60022
INFO[0210] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0210] [hostagent] [VZ] - vm state change: running
INFO[0220] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0221] [hostagent] The essential requirement 1 of 2 is satisfied
INFO[0221] [hostagent] Waiting for the essential requirement 2 of 2: "user session is ready for ssh"
INFO[0221] [hostagent] The essential requirement 2 of 2 is satisfied
INFO[0221] [hostagent] Waiting for the optional requirement 1 of 1: "user probe 1/1"
INFO[0221] [hostagent] Forwarding "/run/user/501/docker.sock" (guest) to "/Users/{user name}/.lima/default/sock/docker.sock" (host)
INFO[0221] [hostagent] Guest agent is running
INFO[0221] [hostagent] Not forwarding TCP 127.0.0.53:53
INFO[0221] [hostagent] Not forwarding TCP 127.0.0.54:53
INFO[0221] [hostagent] Not forwarding TCP [::]:22
INFO[0251] [hostagent] The optional requirement 1 of 1 is satisfied
INFO[0251] [hostagent] Waiting for the guest agent to be running
INFO[0251] [hostagent] Waiting for the final requirement 1 of 1: "boot scripts must have finished"
INFO[0257] [hostagent] The final requirement 1 of 1 is satisfied
INFO[0258] READY. Run `lima` to open the shell.
INFO[0258] Message from the instance "default":
To run `docker` on the host (assumes docker-cli is installed), run the following commands:
------
docker context create lima-default --docker "host=unix:///Users/{user name}/.lima/default/sock/docker.sock"
docker context use lima-default
docker run hello-world
------
echo 'export DOCKER_HOST=unix://$HOME/.lima/default/sock/docker.sock' >> ~/.zshrc
source ~/.zshrc
Hello World
docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c9c5fd25a1bd: Pull complete
Digest: sha256:7e1a4e2d11e2ac7a8c3f768d4166c2defeb09d2a750b010412b6ea13de1efb19
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Docker コマンドのタブ補完ができるようになるまで
以下「Git コマンドのタブ補完ができるようになるまで」を行うと Docker コマンドもタブ補完できるようになる。
docker compose を使えるようになるまで
brew install docker-compose
mkdir -p ~/.docker/cli-plugins
ln -sfn /usr/local/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
% docker compose --version
Docker version 28.0.1, build 068a01ea94
よく見ると Docker のバージョンを出力しているだけでまだ docker compose
は使えなかった。
/usr/local
下に何もいない。
以下で brew
でインストールした docker-compose
のパスを確認すると
brew --prefix docker-compose
以下に配置されていることが分かった。
/opt/homebrew/opt/docker-compose
というわけでシンボリックリンクを以下に変更。
ln -s $(brew --prefix docker-compose)/bin/docker-compose ~/.docker/cli-plugins/docker-compose
docker compose
コマンドが使えるようになった。
% docker compose version
Docker Compose version 2.34.0
※ docker compose
のバージョン確認のコマンドには --
は付けないのね。
コンテナ内からマウントしたホストに書込みができない問題
記事作成予定
VSCode の Dev Containers で Docker が認識されていない問題
% docker context ls
NAME DESCRIPTION DOCKER ENDPOINT ERROR
default * Current DOCKER_HOST based configuration unix:///Users/{user name}/.lima/default/sock/docker.sock
Warning: DOCKER_HOST environment variable overrides the active context. To use a context, either set the global --context flag, or unset DOCKER_HOST environment variable.
VSCode の setting.json に以下追記。(user name は適宜書き換え)
{
"docker.host": "unix:///Users/{user name}/.lima/default/sock/docker.sock"
}
メモリの制限を変更
limactl stop default
limactl edit default
# memory: "8Gib" を追記
limactl start default
このスクラップは11日前にクローズされました
作成者以外のコメントは許可されていません