Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/templates/docker-rootful.yaml
2601 views
1
# A template to use Docker (rootful) instead of containerd & nerdctl
2
# $ limactl start ./docker-rootful.yaml
3
# $ limactl shell docker-roootful 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-rootful --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
- mode: yq
36
path: /etc/systemd/system/docker.socket.d/override.conf
37
format: ini
38
expression: .Socket.SocketUser="{{.User}}"
39
- mode: yq
40
path: "/etc/docker/daemon.json"
41
expression: |
42
.features.cdi = true |
43
.features.containerd-snapshotter = {{.Param.containerdSnapshotter}}
44
probes:
45
- script: |
46
#!/bin/bash
47
set -eux -o pipefail
48
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
49
echo >&2 "docker is not installed yet"
50
exit 1
51
fi
52
if ! timeout 30s bash -c "until pgrep dockerd; do sleep 3; done"; then
53
echo >&2 "dockerd is not running"
54
exit 1
55
fi
56
hint: See "/var/log/cloud-init-output.log" in the guest
57
hostResolver:
58
# hostResolver.hosts requires lima 0.8.3 or later. Names defined here will also
59
# resolve inside containers, and not just inside the VM itself.
60
hosts:
61
host.docker.internal: host.lima.internal
62
portForwards:
63
- guestSocket: "/var/run/docker.sock"
64
hostSocket: "{{.Dir}}/sock/docker.sock"
65
message: |
66
To run `docker` on the host (assumes docker-cli is installed), run the following commands:
67
------
68
docker context create lima-{{.Name}} --docker "host=unix://{{.Dir}}/sock/docker.sock"
69
docker context use lima-{{.Name}}
70
docker run hello-world
71
------
72
{{- if .Instance.Config.VMOpts.vz.rosetta.enabled}}
73
Rosetta is enabled in this VM, so you can run x86_64 containers on Apple Silicon.
74
You can use Rosetta AOT Caching with the CDI spec:
75
- To run a container, add `--device=lima-vm.io/rosetta=cached` to your `docker run` command:
76
------
77
docker run --platform=linux/amd64 --device=lima-vm.io/rosetta=cached ...
78
------
79
- To build an image, add `# syntax=docker/dockerfile:1-labs` at the top of your Dockerfile,
80
and use `--device=lima-vm.io/rosetta=cached` in the `RUN` command:
81
------
82
# syntax=docker/dockerfile:1-labs
83
FROM ...
84
...
85
RUN --device=lima-vm.io/rosetta=cached <your amd64 command>
86
------
87
See: https://lima-vm.io/docs/config/multi-arch/#rosetta-aot-caching
88
{{- end}}
89
param:
90
containerdSnapshotter: true
91
92