macOS で直接、Linux コンテナを実行する
Apple、macOS上でLinuxコンテナを直接実行できる「container」をオープンソースとして公開 で取り上げられていますが、Apple が macOS 上で直接、Linux コンテナを実行出来る仕組みを OSS として公開しました。 関連 URL は以下です。
- Apple supercharges its tools and technologies for developers to foster creativity, innovation, and design
- Containerization
- apple / container
- apple / containerization
Apple supercharges its tools and technologies for developers to foster creativity, innovation, and design の「Containerization Framework」では以下のように説明されています。
The Containerization framework enables developers to create, download, or run Linux container images directly on Mac. It’s built on an open-source framework optimized for Apple silicon and provides secure isolation between container images.
今回は macOS 上へ container をインストールし、Linux コンテナを起動する手順をメモします。
検証環境¶
対象 | バージョン |
---|---|
macOS | Sequoia 15.5 |
container | 0.1.0 (build: release, commit: 0fd8692) |
インストール¶
GitHub の container リリースページ からインストーラをダウンロードすることが出来ます。 今回は container-0.1.0-installer-signed.pkg
をインストールしました。 /usr/local/bin/container
へインストールされました。
container を開始する¶
container を開始せず、Linux コンテナを起動すると以下のエラーになりました。
% container run hello-world
Error: interrupted: "XPC connection error: Connection invalid"
container system start
を実行して container を起動します。 初回だけ、カーネルをダウンロードする必要があります。
% container system start
Verifying apiserver is running...
Installing base container filesystem...
No default kernel configured.
Install the recommended default kernel from [https://github.com/kata-containers/kata-containers/releases/download/3.17.0/kata-static-3.17.0-arm64.tar.xz]? [Y/n]: Y
Installing kernel...
Linux コンテナを実行する¶
hello-world コンテナを実行するとエラーなどは発生せず、実行出来ました。
% container run hello-world
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 と共通のようです。 container ls
でコンテナの一覧を表示出来ました。
% container ls -a
ID IMAGE OS ARCH STATE ADDR
38fda434-e44a-4e2e-99ea-d0cbf6b14554 docker.io/library/hello-world:latest linux arm64 stopped
container は自動起動しない¶
container は自動起動しない為、macOS 自体を再起動した場合は container 自身を起動し直す必要があります。
container system start
参考¶
container のヘルプ¶
% container --help
OVERVIEW: A container platform for macOS
USAGE: container [--debug] <subcommand>
OPTIONS:
--debug Enable debug output [environment: CONTAINER_DEBUG]
--version Show the version.
-h, --help Show help information.
CONTAINER SUBCOMMANDS:
create Create a new container
delete, rm Delete one or more containers
exec Run a new command in a running container
inspect Display information about one or more containers
kill Kill one or more running containers
list, ls List containers
logs Fetch container stdio or boot logs
run Run a container
start Start a container
stop Stop one or more running containers
IMAGE SUBCOMMANDS:
build Build an image from a Dockerfile
images, image, i Manage images
registry, r Manage registry configurations
SYSTEM SUBCOMMANDS:
builder Manage an image builder instance
system, s Manage system components
container system のヘルプ¶
% container system --help
OVERVIEW: Manage system components
USAGE: container system <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
dns Manage local DNS domains
logs Fetch system logs for `container` services
restart Restart API server for `container`
start Start `container` services
stop Stop all `container` services
kernel Manage the default kernel configuration
See 'container help system <subcommand>' for detailed help.