Created
May 1, 2023 16:07
-
-
Save stevenctl/ec04c5f34b4fe0efcb447181d00242f0 to your computer and use it in GitHub Desktop.
This file contains 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
# $ limactl shell docker docker run -it -v $HOME:$HOME --rm alpine | |
# To run `docker` on the host (assumes docker-cli is installed): | |
# $ export DOCKER_HOST=$(limactl list docker --format 'unix://{{.Dir}}/sock/docker.sock') | |
# $ docker ... | |
# This example requires Lima v0.8.0 or later | |
images: | |
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img" | |
arch: "aarch64" | |
mounts: | |
- location: "~/" | |
writable: false | |
- location: "~/go/src" | |
writable: true | |
- location: "~/go/pkg" | |
writable: true | |
- location: "/tmp/lima" | |
writable: true | |
- location: "~/.docker/cli-plugins-linux" | |
mountPoint: "~/.docker/cli-plugins" | |
- location: "~/.docker/cli-plugins" | |
mountPoint: /macplugins | |
writable: true | |
mountType: virtiofs | |
# VM type: "qemu" or "vz" (on macOS 13 and later). | |
# The vmType can be specified only on creating the instance. | |
# The vmType of existing instances cannot be changed. | |
# 🟢 Builtin default: "qemu" | |
vmType: vz | |
# Arch: "default", "x86_64", "aarch64". | |
# 🟢 Builtin default: "default" (corresponds to the host architecture) | |
arch: aarch64 | |
# Below is all required setup for docker in lima | |
# Memory size | |
# 🟢 Builtin default: "4GiB" | |
memory: 8GiB | |
# Disk size | |
# 🟢 Builtin default: "100GiB" | |
disk: 64GiB | |
# 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 | |
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 | |
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: "/run/user/{{.UID}}/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}} | |
docker run hello-world | |
------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment