0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Apple siliconのMacBookにUTMを使ったdocker環境作成

Posted at

やりたいこと

M2 macbookを購入したのでdockerが動く環境を作りたい
boot2dockerのARM版は作れそうもなかったのでArklinuxにしてみる。

前提条件

DockerDesktopは使わない
Docker-cliだけMacに配備する
VSCODEのリモート開発で利用するため、MacのVolumeマウントは行わない

UTMのインストール

公式サイトからインストール

ArklinuxのARM版で仮想マシン作成

公式ギャラリーからUTMで開くボタンを押す
5秒程度で起動するのでboot2dockerに近い使用感だった。

Arklinuxの設定(ssh)

/root/.ssh/authorized_keys にMac側で作成したSSHの公開キーを設定

Arklinuxの設定(dockerd)

arklinuxは以下のインストールshellが使えない。

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh 

代わりにdockerdのバイナリを配備

tar xzvf /path/to/<FILE>.tar.gz
cp docker/* /usr/bin/

このままでは仮想マシン再起動時に自動起動しないのでsystemdに登録する。
docker.service と docker.socket を/etc/systemd/system に配備
conteinerd.service はいったん諦めた。

/etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
#After=network-online.target docker.socket firewalld.service containerd.service
After=network-online.target docker.socket firewalld.service 
Wants=network-online.target
#Requires=docker.socket containerd.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues stil
l
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.soc
k
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 2
29.
# Both the old, and new location are accepted by systemd 229 and up, so using th
e old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 2
30.
# Both the old, and new name are accepted by systemd 230 and up, so using the ol
d name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containe
rs
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target
/etc/systemd/system/docker.socket
[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

起動するか確認

systemctl start docker

host名でMacからアクセスしたいのでavahiをコンテナで起動
docker-hubにARM版があるのが嬉しい

docker run -d --restart always --name avahi --net=host ydkn/avahi:latest

サービス有効化

systemctl enable docker

Mac側でリモートを設定して完了

~/.ssh/config
Host docker-local
  #HostName 192.168.64.4
  HostName alarm.local
  Port 22
  User root
  IdentitiesOnly yes
  IdentityFile ~/.ssh/old_docker_rsa
  ServerAliveInterval 10
  ServerAliveCountMax 3

docker context ls
docker context create local-vm --docker 'host=ssh://docker-local'
docker context use local-vm

さようならboot2odocker
こんにちはarklinux

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?