Skip to content

Commit f72b31f

Browse files
authored
Merge pull request moby#3333 from ktock/stargz-snapshotter-rootless
docs: Enable rootless for stargz-snapshotter
2 parents e81d434 + 8b13218 commit f72b31f

File tree

1 file changed

+122
-33
lines changed

1 file changed

+122
-33
lines changed

docs/stargz-estargz.md

Lines changed: 122 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Lazy pulling stargz/eStargz base images (Experimental)
22

3-
This document describes the configuration that allows buildkit to lazily pull [stargz](https://github.com/google/crfs/blob/master/README.md#introducing-stargz)/[eStargz](https://github.com/containerd/stargz-snapshotter/blob/master/docs/stargz-estargz.md)-formatted images from registries and how to obtain stargz/eStargz images.
3+
This document describes the configuration that allows buildkit to lazily pull [stargz](https://github.com/google/crfs/blob/master/README.md#introducing-stargz)/[eStargz](https://github.com/containerd/stargz-snapshotter/blob/main/docs/estargz.md)-formatted images from registries and how to obtain stargz/eStargz images.
44

55
By default, buildkit doesn't pull images until they are strictly needed.
66
For example, during a build, buildkit doesn't pull the base image until it runs commands on it (e.g. `RUN` Dockerfile instruction) or until it exports stages as tarballs, etc.
@@ -12,28 +12,41 @@ This document describes the configuration and usage of this feature.
1212

1313
For more details about stargz/eStargz image format, please see also [Stargz and eStargz image formats](#stargz-and-estargz-image-formats) section.
1414

15-
## Known limitations
16-
17-
- If you are using containerd worker, stargz snapshotter (`containerd-stargz-grpc`) needs to be run and configured separately.
18-
- Rootless execution is currently unsupported.
19-
2015
## Enabling lazy pulling of stargz/eStargz images
2116

2217
Buildkit supports two ways to enable lazy pulling of stargz/eStargz images.
2318

2419
### Using builtin support (recommended)
2520

21+
- Requirements
22+
- Rootless execution requires kernel >= 5.11 or Ubuntu kernel. BuildKit >= v0.11 is recommended.
23+
2624
OCI worker has builtin support for stargz/eStargz.
2725
You can enable this feature by running `buildkitd` with an option `--oci-worker-snapshotter=stargz`.
2826

2927
```
3028
buildkitd --oci-worker-snapshotter=stargz
3129
```
3230

33-
This is the easiest way to use this lazy pull feature on buildkit.
34-
Currently, this configuration is unsupported for containerd worker.
31+
This is the easiest way to use this lazy pulling feature on buildkit.
3532

36-
#### Example of building an image with lazy pull
33+
#### Builtin stargz snapshotter with rootless
34+
35+
To run it by non-root user, you can use [RootlessKit](https://github.com/rootless-containers/rootlesskit/).
36+
37+
```
38+
rootlesskit buildkitd --oci-worker-snapshotter=stargz
39+
```
40+
41+
```
42+
buildctl --addr unix:///run/user/$UID/buildkit/buildkitd.sock build ...
43+
```
44+
45+
> NOTE1: For details about rootless configuration, see [`/docs/rootless.md`](./rootless.md).
46+
47+
> NOTE2: If buildkitd can't create directory or socket under `/run`, check if `$XDG_RUNTIME_DIR` is set correctly (e.g. typically `/run/user/$UID`)
48+
49+
#### Example of building an image with lazy pulling
3750

3851
Once `buildkitd` starts with the above configuration, stargz/eStargz images can be lazily pulled.
3952
For example, we build the following golang binary with buildkit.
@@ -83,24 +96,16 @@ However if the destination is a registry and the target repository already conta
8396

8497
### Using proxy (standalone) snapshotter
8598

86-
This is another way to enable stargz-based lazy pull.
87-
[Stargz Snapshotter (`containerd-stargz-grpc`)](https://github.com/containerd/stargz-snapshotter) needs to be installed.
88-
Note that buildkit's registry configuration doesn't propagate to stargz snapshotter so it needs to be configured separately when you use private/mirror repositories.
99+
This is another way to enable stargz-based lazy pulling.
100+
This configuration is for users of containerd worker.
89101

90-
This configuration is for users of containerd worker and ones trying other versions of stargz snapshotter than built into OCI worker.
102+
- Requirements
103+
- [Stargz Snapshotter (`containerd-stargz-grpc`)](https://github.com/containerd/stargz-snapshotter) needs to be installed. stargz-snapshotter >= v0.13 is recommended.
104+
- Rootless execution requires kernel >= 5.11 or Ubuntu kernel. BuildKit >= v0.11 is recommended.
91105

92-
#### With OCI worker
93-
94-
Spawn `containerd-stargz-grpc` as a separated process.
95-
Then run `buildkitd` with an option `--oci-worker-proxy-snapshotter-path=/run/containerd-stargz-grpc/containerd-stargz-grpc.sock` which makes it recognize this snapshotter via the socket.
96-
97-
```
98-
containerd-stargz-grpc
99-
buildkitd --oci-worker-snapshotter=stargz \
100-
--oci-worker-proxy-snapshotter-path=/run/containerd-stargz-grpc/containerd-stargz-grpc.sock
101-
```
106+
> NOTE: BuildKit's registry configuration isn't propagated to the proxy stargz snapshotter so it needs to be configured separately when you use private/mirror registries. If you use OCI worker + builtin stargz snapshotter, the separated configurations isn't needed.
102107
103-
#### With containerd worker
108+
#### Proxy snapshotter with containerd worker
104109

105110
Configure containerd's config.toml (default = `/etc/containerd/config.toml`) to make it recognize stargz snapshotter as a [proxy snapshotter](https://github.com/containerd/containerd/blob/master/PLUGINS.md#proxy-plugins).
106111

@@ -119,11 +124,90 @@ containerd
119124
buildkitd --containerd-worker-snapshotter=stargz --oci-worker=false --containerd-worker=true
120125
```
121126

122-
#### Registry-related configurations for standalone stargz snapshotter
127+
#### Proxy snapshotter with rootless containerd worker
128+
129+
To run it by non-root user, you can use `containerd-rootless-setuptool.sh` included in [containerd/nerdctl](https://github.com/containerd/nerdctl).
130+
131+
`install` subcommand installs rootless containerd.
132+
133+
```
134+
containerd-rootless-setuptool.sh install
135+
```
136+
137+
`install-stargz` subcommand installs rootless stargz-snapshotter.
138+
139+
```
140+
$ containerd-rootless-setuptool.sh install-stargz
141+
$ cat <<'EOF' >> ~/.config/containerd/config.toml
142+
[proxy_plugins]
143+
[proxy_plugins."stargz"]
144+
type = "snapshot"
145+
address = "/run/user/1000/containerd-stargz-grpc/containerd-stargz-grpc.sock"
146+
EOF
147+
$ systemctl --user restart containerd.service
148+
```
149+
150+
> NOTE: replace "1000" with your actual UID
151+
152+
[`install-buildkit-containerd` subcommand](https://github.com/containerd/nerdctl/blob/v1.0.0/docs/build.md#setting-up-buildkit-with-containerd-worker) installs rootless buildkitd with containerd worker.
153+
`CONTAINERD_SNAPSHOTTER=stargz` enables stargz-snapshotter.
154+
`CONTAINERD_NAMESPACE` specifies containerd namespace used by BuildKit.
155+
156+
```
157+
$ CONTAINERD_NAMESPACE=default CONTAINERD_SNAPSHOTTER=stargz containerd-rootless-setuptool.sh install-buildkit-containerd
158+
```
159+
160+
> NOTE: `CONTAINERD_SNAPSHOTTER=stargz` doesn't work with nerdctl <= v1.0.0.
161+
162+
```
163+
buildctl --addr unix:///run/user/1000/buildkit-default/buildkitd.sock build ...
164+
```
165+
166+
#### Proxy snapshotter with OCI worker
167+
168+
Spawn `containerd-stargz-grpc` as a separated process.
169+
Then specify stargz-snapshotter's socket path to `--oci-worker-proxy-snapshotter-path`.
170+
171+
```
172+
containerd-stargz-grpc
173+
buildkitd --oci-worker-snapshotter=stargz \
174+
--oci-worker-proxy-snapshotter-path=/run/containerd-stargz-grpc/containerd-stargz-grpc.sock
175+
```
176+
177+
#### Proxy snapshotter with rootless OCI worker
178+
179+
Run stargz-snapshotter with rootlesskit.
180+
181+
```
182+
rootlesskit --state-dir=/run/user/$UID/rootlesskit-buildkit \
183+
containerd-stargz-grpc --root=$HOME/.local/share/containerd-stargz-grpc \
184+
--address=/run/user/$UID/containerd-stargz-grpc/containerd-stargz-grpc.sock &
185+
```
186+
187+
RootlessKit writes the PID to a file named `child_pid` under `--state-dir` directory.
188+
189+
Join buildkitd to the same rootlesskit namespace.
190+
Specify stargz-snapshotter's socket path to `--oci-worker-proxy-snapshotter-path`.
191+
192+
```
193+
nsenter -U --preserve-credentials -m -t $(cat /run/user/$UID/rootlesskit-buildkit/child_pid) \
194+
buildkitd --oci-worker-snapshotter=stargz \
195+
--oci-worker-proxy-snapshotter-path=/run/user/$UID/containerd-stargz-grpc/containerd-stargz-grpc.sock &
196+
```
197+
198+
> NOTE: If buildkitd can't create directory or socket under `/run`, check if `$XDG_RUNTIME_DIR` is set correctly (e.g. typically `/run/user/$UID`)
199+
200+
```
201+
buildctl --addr unix:///run/user/$UID/buildkit/buildkitd.sock build ...
202+
```
203+
204+
#### Registry-related configurations for proxy (standalone) stargz snapshotter
205+
206+
> NOTE: You don't need this configuration if you use OCI worker + builtin stargz snapshotter
123207
124208
When you use standalone stargz snapshotter, registry configuration needs to be done for the stargz snapshotter process, separately.
125209
Create a configuration toml file which contains the registry configuration for stargz snapshotter (e.g. `/etc/containerd-stargz-grpc/config.toml`).
126-
The configuration format [**differs** from buildkit](https://github.com/containerd/stargz-snapshotter/blob/master/cmd/containerd-stargz-grpc/config.go).
210+
The configuration format [differs from buildkit](https://github.com/containerd/stargz-snapshotter/blob/master/cmd/containerd-stargz-grpc/config.go).
127211
For more information about this format, please see also [docs in the repository](https://github.com/containerd/stargz-snapshotter/blob/master/docs/overview.md#registry-related-configuration).
128212

129213
```toml
@@ -139,20 +223,23 @@ containerd-stargz-grpc --config=/etc/containerd-stargz-grpc/config.toml
139223

140224
## Stargz and eStargz image formats
141225

142-
[Stargz](https://github.com/google/crfs/blob/master/README.md#introducing-stargz) and [eStargz](https://github.com/containerd/stargz-snapshotter/blob/master/docs/stargz-estargz.md) are OCI/Docker-compatible image formats that can be lazily pulled from standard registries (e.g. Docker Hub, GitHub Container Registry, etc).
226+
[Stargz](https://github.com/google/crfs/blob/master/README.md#introducing-stargz) and [eStargz](https://github.com/containerd/stargz-snapshotter/blob/main/docs/estargz.md) are OCI/Docker-compatible image formats that can be lazily pulled from standard registries (e.g. Docker Hub, GitHub Container Registry, etc).
143227
Because they are backwards-compatible to OCI/Docker images, they can run on standard runtimes (e.g. Docker, containerd, etc.).
144228
Stargz is proposed by [Google CRFS project](https://github.com/google/crfs).
145229
eStargz is an extended format of stargz by [Stargz Snapshotter](https://github.com/containerd/stargz-snapshotter).
146-
It comes with [additional features](https://github.com/containerd/stargz-snapshotter/blob/master/docs/stargz-estargz.md#estargz-archive-format) including chunk verification and prefetch for avoiding the overhead of on-demand fetching.
147-
For more details about lazy pull with stargz/eStargz images, please refer to the docs on these repositories.
230+
It comes with [additional features](https://github.com/containerd/stargz-snapshotter/blob/main/docs/estargz.md) including chunk verification and prefetch for avoiding the overhead of on-demand fetching.
231+
For more details about lazy pulling with stargz/eStargz images, please refer to the docs on these repositories.
148232

149233
## Creating stargz/eStargz images
150234

151235
### Building eStargz image with BuildKit
152236

153237
BuildKit supports creating eStargz as one of the compression types.
238+
239+
:information_source: Creating eStargz image does NOT require [stargz-snapshotter setup](#enabling-lazy-pulling-of-stargzeStargz-images).
240+
154241
As shown in the following, `compression=estargz` creates an eStargz-formatted image.
155-
Specifying `oci-mediatypes=true` option is highly recommended for enabling [layer verification](https://github.com/containerd/stargz-snapshotter/blob/v0.6.4/docs/verification.md) of eStargz.
242+
Specifying `oci-mediatypes=true` option is highly recommended for enabling [layer verification](https://github.com/containerd/stargz-snapshotter/blob/v0.13.0/docs/estargz.md#content-verification-in-estargz) of eStargz.
156243

157244
```
158245
buildctl build ... \
@@ -167,12 +254,14 @@ buildctl build ... \
167254

168255
### Other methods to obtain stargz/eStargz images
169256

170-
Pre-converted stargz/eStargz images are available at [`ghcr.io/stargz-containers` repository](https://github.com/containerd/stargz-snapshotter/blob/master/docs/pre-converted-images.md) (mainly for testing purpose).
257+
Pre-converted stargz/eStargz images are available at [`ghcr.io/stargz-containers` repository](https://github.com/containerd/stargz-snapshotter/blob/main/docs/pre-converted-images.md) (mainly for testing purpose).
171258

172259
You can also create any stargz/eStargz image using the variety of tools including the following.
173260

174-
- [`nerdctl`](https://github.com/containerd/nerdctl/blob/v0.10.0/docs/stargz.md#building-stargz-images-using-nerdctl-build): Docker-compatible CLI for containerd and BuildKit. This supports `convert` subcommand to convert an OCI/Docker image into eStargz.
175-
- [`ctr-remote`](https://github.com/containerd/stargz-snapshotter/blob/v0.6.4/docs/ctr-remote.md): containerd CLI developed in stargz snapshotter project. This supports converting an OCI/Docker image into eStargz and [optimizing](https://github.com/containerd/stargz-snapshotter/blob/v0.6.4/docs/stargz-estargz.md#example-use-case-of-prioritized-files-workload-based-image-optimization-in-stargz-snapshotter) it.
261+
- [Docker Buildx](https://github.com/containerd/stargz-snapshotter/tree/v0.13.0#building-estargz-images-using-buildkit): Docker CLI plugin for BuildKit.
262+
- [Kaniko](https://github.com/containerd/stargz-snapshotter/tree/v0.13.0#building-estargz-images-using-kaniko): An image builder runnable in containers and Kubernetes.
263+
- [nerdctl](https://github.com/containerd/nerdctl/blob/v1.0.0/docs/stargz.md#building-stargz-images-using-nerdctl-build): Docker-compatible CLI for containerd and BuildKit. This supports `convert` subcommand to convert an OCI/Docker image into eStargz.
264+
- [`ctr-remote`](https://github.com/containerd/stargz-snapshotter/blob/v0.13.0/docs/ctr-remote.md): containerd CLI developed in stargz snapshotter project. This supports converting an OCI/Docker image into eStargz and [optimizing](https://github.com/containerd/stargz-snapshotter/blob/v0.13.0/docs/estargz.md#example-use-case-of-prioritized-files-workload-based-image-optimization-in-stargz-snapshotter) it.
176265
- [`stargzify`](https://github.com/google/crfs/tree/master/stargz/stargzify): CLI tool to convert an OCI/Docker image to stargz. This is developed in CRFS project. Creating eStargz is unsupported.
177266

178267
There also other tools including Kaniko, ko, builpacks.io that support eStargz creation.

0 commit comments

Comments
 (0)