Docker Desktop for Mac and Windows有償化に伴い、cliで現開発環境が稼働できるように、M1 Macで実施したので備忘録がてら残す。
※MySQL5.7対応でかなりハマったのは内緒の話。
構成
lima + dockerを使用した形を採用。
ホストマシンの上にLima(Virtual Machine)を立ち上げて、その中のDocker Engineを使用する構成。
手順
Docker Install
brew install docker
※ Docker fot Desktop経由でインストール済みの場合はどうにかしてアンインストールすること。
lima Install
brew install lima
docker-compose install
執筆当時(20220119)はhomebrew経由でのinstallはできないようなので、物理ファイルを落とす。
# https://github.com/docker/compose/releases/
wget https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-$(uname -s)-$(uname -m)
sudo mv docker-compose-$(uname -s)-$(uname -m) /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose
lima setting
# 任意のPathでOK
mkdir -p ~/local/lima
vim ~/local/lima/develop-docker.yml
develop-docker.yml
cpus: 4
memory: "8GiB"
disk: "100GiB"
images:
- location: "https://cloud-images.ubuntu.com/hirsute/current/hirsute-server-cloudimg-amd64.img"
arch: "x86_64"
- location: "https://cloud-images.ubuntu.com/hirsute/current/hirsute-server-cloudimg-arm64.img"
arch: "aarch64"
mounts: # プロジェクトを追加
- location: "~/git"
writable: true
containerd:
system: false
user: false
provision:
- mode: system
script: |
#!/bin/sh
sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts
- mode: system
script: |
#!/bin/bash
set -eux -o pipefail
command -v docker >/dev/null 2>&1 && exit 0
export DEBIAN_FRONTEND=noninteractive
curl -fsSL https://get.docker.com | sh
# NOTE: you may remove the lines below, if you prefer to use rootful docker, not rootless
systemctl disable --now docker
apt-get install -y uidmap dbus-user-session
- mode: user
script: |
#!/bin/bash
set -eux -o pipefail
systemctl --user start dbus
dockerd-rootless-setuptool.sh install
docker context use rootless
probes:
- script: |
#!/bin/bash
set -eux -o pipefail
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
echo >&2 "docker is not installed yet"
exit 1
fi
if ! timeout 30s bash -c "until pgrep rootlesskit; do sleep 3; done"; then
echo >&2 "rootlesskit (used by rootless docker) is not running"
exit 1
fi
hint: See "/var/log/cloud-init-output.log". in the guest
portForwards:
- guestSocket: "/run/user/{{.UID}}/docker.sock"
hostSocket: "{{.Dir}}/sock/docker.sock"
message: |
Success.
limactl start ~/local/lima/develop-docker.yml
> 脳死 Enter
echo 'export DOCKER_HOST=$(limactl list develop-docker --format unix://{{.Dir}}/sock/docker.sock)' >> .bash_profile
# 疎通確認(正常に実行できればOK)
docker --version
docker-compose --version