Last active
December 31, 2023 15:25
-
-
Save queses/6419d849e36bbb96c4d90f7978a0279b to your computer and use it in GitHub Desktop.
LimaVM template: Docker + Alpine + vzNAT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install: | |
# brew install lima | |
# | |
# Install Docker CLI if it's not installed: | |
# brew install docker docker-compose docker-buildx docker-credential-helper | |
# ln -sfn /opt/homebrew/opt/docker-buildx/bin/docker-buildx ~/.docker/cli-plugins/docker-buildx | |
# ln -sfn /opt/homebrew/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose | |
# | |
# Create the VM: | |
# limactl create --name=myvm docker-alpine-vznat.template.yaml | |
# | |
# Start the VM: | |
# limactl start myvm | |
# | |
# Stop the VM: | |
# limactl stop myvm | |
vmType: "vz" | |
mountType: "virtiofs" | |
rosetta: | |
enabled: true | |
binfmt: true | |
# Adjust for your needs: | |
cpus: 2 | |
memory: "4GiB" | |
disk: "120GiB" | |
mounts: | |
- location: "~" | |
writable: true | |
- location: "/tmp/lima" | |
writable: true | |
# Adjust for your needs: | |
- location: "/Volumes/Maxim/Code" | |
writable: true | |
# This template requires Lima >= v0.14, macOS >= v13.0 | |
# New image versions: https://github.com/lima-vm/lima/blob/master/examples/alpine.yaml | |
images: | |
- location: "https://github.com/lima-vm/alpine-lima/releases/download/v0.2.32/alpine-lima-std-3.18.0-x86_64.iso" | |
arch: "x86_64" | |
digest: "sha512:7b00fff78736a27a24e4a7de5f28037e9c7cf0fc539a33ec551c6ac619eb54237b5f25bfa35512fa7233cf23396dc249592710ef9150f619afa15267f9c8cbd4" | |
- location: "https://github.com/lima-vm/alpine-lima/releases/download/v0.2.32/alpine-lima-std-3.18.0-aarch64.iso" | |
arch: "aarch64" | |
digest: "sha512:bf23a22e05854670eef74d9bfad056caa249832f22d5594eb6bb02fa9aae109d33c764242f862d48de5b6715c4792a3ee29c19888a0711fb27113ba5cf1ccf21" | |
# Enable vzNAT: | |
networks: | |
- vzNAT: true | |
# containerd is managed by Docker, not by Lima, so the values are set to false here. | |
containerd: | |
system: false | |
user: false | |
provision: | |
- mode: system | |
# This script defines the host.docker.internal hostname when hostResolver is disabled. | |
# It is also needed for lima 0.8.2 and earlier, which does not support hostResolver.hosts. | |
# Names defined in /etc/hosts inside the VM are not resolved inside containers when | |
# using the hostResolver; use hostResolver.hosts instead (requires lima 0.8.3 or later). | |
script: | | |
#!/bin/sh | |
sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts | |
- mode: system | |
script: | | |
#!/bin/bash | |
apk add docker openrc | |
rc-update add docker boot | |
addgroup ${LIMA_CIDATA_USER} docker | |
- mode: system | |
script: | | |
#!/bin/bash | |
sudo service docker start | |
probes: | |
- mode: readiness | |
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 dockerd; do sleep 3; done"; then | |
echo >&2 "dockerd is not running" | |
exit 1 | |
fi | |
hostResolver: | |
# hostResolver.hosts requires lima 0.8.3 or later. Names defined here will also | |
# resolve inside containers, and not just inside the VM itself. | |
hosts: | |
host.docker.internal: host.lima.internal | |
portForwards: | |
- guestSocket: "/var/run/docker.sock" | |
hostSocket: "{{.Dir}}/sock/docker.sock" | |
message: | | |
To run `docker` on the host (assumes docker-cli is installed), run the following commands: | |
------ | |
docker context create lima-{{.Name}} --docker "host=unix://{{.Dir}}/sock/docker.sock" | |
docker context use lima-{{.Name}} | |
# alternatively, for use with "default" context: | |
export DOCKER_HOST=$(limactl list {{.Name}} --format 'unix://{{.Dir}}/sock/docker.sock') | |
docker run hello-world | |
------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment