13
14

More than 1 year has passed since last update.

Mac + Lima + Docker

Last updated at Posted at 2022-03-07

会社の先輩T氏に Docker Desktop for Mac を使わず
Dockerが利用できる方法を教えてもらったので自分のプラベートMacにインストールした覚書

Lima と Docer をインストール

% brew install lima docker

docker-compose を使う予定がある場合

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 up -d

LimaのにDockerサンプルファイルをもってくる

インストールしたバージョンと同一のものを lima-vm/lima からもってくる

% limactl -v
limactl version 0.8.3

% curl -o docker.yaml https://raw.githubusercontent.com/lima-vm/lima/v0.8.3/examples/docker.yaml

初回起動

% limactl start ./docker.yaml

初回尋ねられるので Proceed with the default configuration を選択

? Creating an instance "default"  [Use arrows to move, type to filter]
> Proceed with the default configuration
  Open an editor to override the configuration

インストールが完了すると↓のメッセージが表示される。

To run `docker` on the host (assumes docker-cli is installed), run the following commands:
------
docker context create lima --docker "host=unix:///Users/mykysyk/.lima/docker/sock/docker.sock"
docker context use lima
docker run hello-world
------

DOCKER_HOST を 起動したlimaのUnixソケットを指定した環境変数 を.zshrcに追記する

% echo 'export DOCKER_HOST=unix://$HOME/.lima/docker/sock/docker.sock' >> ~/.zshrc
% source  ~/.zshrc

nginxを起動してみる

% docker ps --all
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

% docker pull nginx
% docker run nginx -p 8080:80
% docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED              STATUS              PORTS                                   NAMES
8f914543a791   nginx     "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:8888->80/tcp, :::8888->80/tcp   blissful_cerf

http://127.0.0.1:8888/ にアクセスして↓がブラウザに表示されたら成功

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

ボリュームマウントしたディレクトリに書き込むと Read-only file system となる場合

Docker停止

% limactl stop docker

lima.yaml 設定ファイルを編集

% ~/.lima/docker/lima.yaml

↓を追加

mounts:
- location: /path/to/shared/dir
  writable: true

Docker起動

% limactl start docker

書き込めるかテスト

% cd /path/to/shared/dir
% docker pull alpine:latest
% docker run -it --rm -v $(pwd):/home alpine:latest /bin/sh
# touch /home/a
# ls /home/a

ディスク使用量

インストールするには約3G〜程必要

Used 136Gi -> 139Gi 

limactl

DockerVMの状態確認

% limactl list
NAME      STATUS     SSH                ARCH      CPUS    MEMORY    DISK      DIR
docker    Running    127.0.0.1:52785    x86_64    4       4GiB      100GiB    /Users/mykysyk/.lima/docker

DockerVMのシェルにはいる

% limactl shell docker

DockerVMの停止

% limactl stop docker

DockerVMの起動(2回目以降)

% limactl start docker

DockerVMの削除

% limactl delete docker
13
14
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
14