Skip to content

Commit af36c29

Browse files
committed
templates: add docker-rootful
Signed-off-by: Akihiro Suda <[email protected]>
1 parent e75b0ea commit af36c29

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Distro:
2020

2121
Container engines:
2222
- [`docker.yaml`](./docker.yaml): Docker
23+
- [`docker-rootful.yaml`](./docker-rootful.yaml): Docker (rootful)
2324
- [`podman.yaml`](./podman.yaml): Podman
2425
- [`singularity.yaml`](./singularity.yaml): Singularity
2526
- LXD is installed in the default Ubuntu template, so there is no `lxd.yaml`

examples/docker-rootful.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Example 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+
# This example requires Lima v0.8.0 or later
10+
images:
11+
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
12+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220712/ubuntu-22.04-server-cloudimg-amd64.img"
13+
arch: "x86_64"
14+
digest: "sha256:86481acb9dbd62e3e93b49eb19a40c66c8aa07f07eff10af20ddf355a317e29f"
15+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220712/ubuntu-22.04-server-cloudimg-arm64.img"
16+
arch: "aarch64"
17+
digest: "sha256:e1ce033239f0038dca5ef09e582762ba0d0dfdedc1d329bc51bb0e9f5057af9d"
18+
# Fallback to the latest release image.
19+
# Hint: run `limactl prune` to invalidate the cache
20+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
21+
arch: "x86_64"
22+
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img"
23+
arch: "aarch64"
24+
25+
mounts:
26+
- location: "~"
27+
- location: "/tmp/lima"
28+
writable: true
29+
# containerd is managed by Docker, not by Lima, so the values are set to false here.
30+
containerd:
31+
system: false
32+
user: false
33+
provision:
34+
- mode: system
35+
# This script defines the host.docker.internal hostname when hostResolver is disabled.
36+
# It is also needed for lima 0.8.2 and earlier, which does not support hostResolver.hosts.
37+
# Names defined in /etc/hosts inside the VM are not resolved inside containers when
38+
# using the hostResolver; use hostResolver.hosts instead (requires lima 0.8.3 or later).
39+
script: |
40+
#!/bin/sh
41+
sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts
42+
- mode: system
43+
script: |
44+
#!/bin/bash
45+
set -eux -o pipefail
46+
command -v docker >/dev/null 2>&1 && exit 0
47+
if [ ! -e /etc/systemd/system/docker.socket.d/override.conf ]; then
48+
mkdir -p /etc/systemd/system/docker.socket.d
49+
# Alternatively we could just add the user to the "docker" group, but that requires restarting the user session
50+
cat <<-EOF >/etc/systemd/system/docker.socket.d/override.conf
51+
[Socket]
52+
SocketUser=${LIMA_CIDATA_USER}
53+
EOF
54+
fi
55+
export DEBIAN_FRONTEND=noninteractive
56+
curl -fsSL https://get.docker.com | sh
57+
probes:
58+
- script: |
59+
#!/bin/bash
60+
set -eux -o pipefail
61+
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
62+
echo >&2 "docker is not installed yet"
63+
exit 1
64+
fi
65+
if ! timeout 30s bash -c "until pgrep dockerd; do sleep 3; done"; then
66+
echo >&2 "dockerd is not running"
67+
exit 1
68+
fi
69+
hint: See "/var/log/cloud-init-output.log". in the guest
70+
hostResolver:
71+
# hostResolver.hosts requires lima 0.8.3 or later. Names defined here will also
72+
# resolve inside containers, and not just inside the VM itself.
73+
hosts:
74+
host.docker.internal: host.lima.internal
75+
portForwards:
76+
- guestSocket: "/var/run/docker.sock"
77+
hostSocket: "{{.Dir}}/sock/docker.sock"
78+
message: |
79+
To run `docker` on the host (assumes docker-cli is installed), run the following commands:
80+
------
81+
docker context create lima-{{.Name}} --docker "host=unix://{{.Dir}}/sock/docker.sock"
82+
docker context use lima-{{.Name}}
83+
docker run hello-world
84+
------

0 commit comments

Comments
 (0)