Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/templates/docker.yaml
2601 views
1
# A template to use Docker instead of containerd & nerdctl
2
# $ limactl start ./docker.yaml
3
# $ limactl shell docker docker run -it -v $HOME:$HOME --rm alpine
4
5
# To run `docker` on the host (assumes docker-cli is installed):
6
# $ export DOCKER_HOST=$(limactl list docker --format 'unix://{{.Dir}}/sock/docker.sock')
7
# $ docker ...
8
9
minimumLimaVersion: 2.0.0
10
11
base:
12
- template:_images/ubuntu-lts
13
- template:_default/mounts
14
15
# containerd is managed by Docker, not by Lima, so the values are set to false here.
16
containerd:
17
system: false
18
user: false
19
provision:
20
- mode: system
21
# This script defines the host.docker.internal hostname when hostResolver is disabled.
22
# It is also needed for lima 0.8.2 and earlier, which does not support hostResolver.hosts.
23
# Names defined in /etc/hosts inside the VM are not resolved inside containers when
24
# using the hostResolver; use hostResolver.hosts instead (requires lima 0.8.3 or later).
25
script: |
26
#!/bin/sh
27
sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts
28
- mode: system
29
script: |
30
#!/bin/bash
31
set -eux -o pipefail
32
command -v docker >/dev/null 2>&1 && exit 0
33
export DEBIAN_FRONTEND=noninteractive
34
curl -fsSL https://get.docker.com | sh
35
# NOTE: you may remove the lines below, if you prefer to use rootful docker, not rootless
36
systemctl disable --now docker
37
apt-get install -y uidmap dbus-user-session
38
- mode: yq
39
path: "{{.Home}}/.config/docker/daemon.json"
40
expression: |
41
.features.cdi = true |
42
.features.containerd-snapshotter = {{.Param.containerdSnapshotter}}
43
owner: "{{.User}}"
44
- mode: user
45
script: |
46
#!/bin/bash
47
set -eux -o pipefail
48
systemctl --user start dbus
49
dockerd-rootless-setuptool.sh install
50
docker context use rootless
51
probes:
52
- script: |
53
#!/bin/bash
54
set -eux -o pipefail
55
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
56
echo >&2 "docker is not installed yet"
57
exit 1
58
fi
59
if ! timeout 30s bash -c "until pgrep rootlesskit; do sleep 3; done"; then
60
echo >&2 "rootlesskit (used by rootless docker) is not running"
61
exit 1
62
fi
63
hint: See "/var/log/cloud-init-output.log" in the guest
64
hostResolver:
65
# hostResolver.hosts requires lima 0.8.3 or later. Names defined here will also
66
# resolve inside containers, and not just inside the VM itself.
67
hosts:
68
host.docker.internal: host.lima.internal
69
portForwards:
70
- guestSocket: "/run/user/{{.UID}}/docker.sock"
71
hostSocket: "{{.Dir}}/sock/docker.sock"
72
message: |
73
To run `docker` on the host (assumes docker-cli is installed), run the following commands:
74
------
75
docker context create lima-{{.Name}} --docker "host=unix://{{.Dir}}/sock/docker.sock"
76
docker context use lima-{{.Name}}
77
docker run hello-world
78
------
79
{{- if .Instance.Config.VMOpts.vz.rosetta.enabled}}
80
Rosetta is enabled in this VM, so you can run x86_64 containers on Apple Silicon.
81
You can use Rosetta AOT Caching with the CDI spec:
82
- To run a container, add `--device=lima-vm.io/rosetta=cached` to your `docker run` command:
83
------
84
docker run --platform=linux/amd64 --device=lima-vm.io/rosetta=cached ...
85
------
86
- To build an image, add `# syntax=docker/dockerfile:1-labs` at the top of your Dockerfile,
87
and use `--device=lima-vm.io/rosetta=cached` in the `RUN` command:
88
------
89
# syntax=docker/dockerfile:1-labs
90
FROM ...
91
...
92
RUN --device=lima-vm.io/rosetta=cached <your amd64 command>
93
------
94
See: https://lima-vm.io/docs/config/multi-arch/#rosetta-aot-caching
95
{{- end}}
96
param:
97
containerdSnapshotter: true
98
99