Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions content/en/docs/docker-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,26 @@ The runner runs as root, or as a user that a polkit rule lets through.
a copy to or from it is refused until it starts.
- Images: list, inspect, history, pull (`POST /images/create`), remove and prune.
A record pulled or built that never ran is an image, not a container; a machine
made from it is a container. An image's ID is its config's digest. An image built
made from it is a container. An image's ID is its config's digest. An image made
here with a name without a registry (`nspawn build -t somos/app:1`, which nspawn
files as `hub.nspawn.org/somos/app:1`) goes by that short name too while Docker
Hub's image of it is not here, so `docker run somos/app:1` finds it.
- Archives: `docker save` and `docker load` (`GET /images/get`, `GET
/images/{name}/get`, `POST /images/load`) write and read the archive of
[nspawn save](/docs/reference/#save) and [load](/docs/reference/#load);
`docker commit` and `docker export` (`POST /commit`, `GET
/containers/{id}/export`) commit and export a container as nspawn does, and
`docker import` (`POST /images/create` with `fromSrc=-`) imports the tar in the
request. A commit names its image as the engine's clients do, one without a
registry being Docker Hub's, and a config in its body that sets anything is
refused with 400, as is a commit without a repository; an import from a URL
answers 501.
- Volumes and networks: list, inspect, create, remove and prune; connect and
disconnect with aliases and fixed addresses. `bridge`, `host` and `none` are the
pre-defined networks.

Builds, loads, imports, tags, pushes and commits of images, container renames and
exports, swarm and plugins answer 501 with "not supported".
Builds, tags and pushes of images, container renames, swarm and plugins answer
501 with "not supported".

A name the API takes that is no machine name, such as `reaper_1`, stays the
container's name in the API, and its machine gets one made of it (`reaper-1-` and
Expand Down
57 changes: 55 additions & 2 deletions content/en/docs/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ weight: 3
description: >-
Image references, the hub and Docker Hub, search and credentials, what pull
does, the storage backends, boot and app detection, more machines from one
image, and where everything lives on disk.
image, images without a registry, and where everything lives on disk.
---

## References
Expand Down Expand Up @@ -287,6 +287,59 @@ before anything is made, so a refused `create` leaves nothing behind.
`pull --name` also makes another machine of an image, but resolves the manifest
through the registry first.

## Images without a registry

```text
$ sudo nspawn commit web somos/web:2 -m "the site's content"
committing web
sha256:053546dc4606b1911aa1cce25bacc5778505984d59a746a15d094f822be7bba0
$ sudo nspawn save -o web.tar somos/web:2 docker.io/library/nginx:latest
saving hub.nspawn.org/somos/web:2
saving docker.io/library/nginx:latest
```

and on another host:

```text
$ sudo nspawn load -i web.tar
Loaded image: hub.nspawn.org/somos/web:2
Loaded image: docker.io/library/nginx:latest
```

`save` writes images to one tar archive, an OCI image layout with the
`manifest.json` of the Docker image archive beside it, so that `nspawn load` and
`docker load` both read it; the layers go as the store keeps them, so a pulled
image keeps the digests its registry gave it. An image is named by its local
name or its reference, and a machine made from it holds it when no image of it
is left, as `web` holds nginx's above. `load` adds the images of such an
archive or of one `docker save` wrote, plain or compressed with gzip, zstd or
bzip2, after checking the whole archive, each under the name its reference
gives.

`commit` makes an image of what a machine changed over its image, with the
machine's settings on top of the image's; `-c` sets more of them with
Dockerfile instructions. A running machine is frozen while its files are read.
The new layer is owned as the image owns its files, whatever user namespace
the machine runs in, and leaves out volumes, binds and tmpfs and what nspawn and
systemd-nspawn write for the machine (`/etc/hosts`, `/etc/resolv.conf`,
`/etc/hostname`, `/etc/machine-id`, `/etc/localtime`). `export` writes a
machine's whole tree as a tar, and `import` makes an image of one layer from
such a tar:

```text
$ sudo nspawn export web -o web-files.tar
exporting web
$ sudo nspawn import web-files.tar somos/web-flat:1 -c 'CMD ["nginx", "-g", "daemon off;"]'
importing hub.nspawn.org/somos/web-flat:1
sha256:71968e5e84aad873c27ab57eea0f5468c0f49ad7fa7f209df918de966586c63f
```

An image committed, loaded or imported is made on this host, as a built one
is: [auto-update](/docs/docker-api/#auto-update) leaves it alone, and
[generate](/docs/machines/#the-same-machines-on-another-host) says to push it,
or carry it over with `save` and `load`, before its script runs elsewhere. See
the [reference](/docs/reference/#save) for every option.

## Listing and removing

```shell
Expand All @@ -303,7 +356,7 @@ sudo nspawn images ls

The list comes from systemd-machined, so it includes images nspawn did not
create (`old-arch` above, with `-` in the nspawn columns). `ORIGIN` is `pull`,
`build` or `create`.
`build`, `commit`, `load`, `import` or `create`.

```shell
sudo nspawn images rm NAME|REFERENCE...
Expand Down
21 changes: 14 additions & 7 deletions content/en/docs/machines.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ starts with a dash comes after `--`. Without `-d` it stays with the machine:
A signal from elsewhere (a crash, a kill from inside the machine, Ctrl-C with
`-t`) gives 255 there. A program that is PID 1 ends with 1 whatever signal
killed it but `kill`'s SIGKILL (137), which is how systemd-nspawn ends then.
`run` exits once the machine is down, the hooks of its unit after the end
done, so `ps` and `inspect` show it ended right after.
Ctrl-C, SIGTERM, SIGHUP and SIGQUIT go to the program; a third Ctrl-C within a
second leaves the machine running and returns.
- `-i` gives the program this standard input, `-t` a terminal; closing that
Expand Down Expand Up @@ -791,7 +793,9 @@ not:
what was copied before it stays copied.

A stopped overlay or flat machine can be copied into and out of; a stopped
`mstack` machine cannot, since its tree only exists while it runs. A stopped
`mstack` machine cannot, since its tree only exists while it runs, and a
machine systemd is starting (`machinectl start`, the dependency of another
machine) is refused until it runs. A stopped
machine's volumes are mounted only while it runs, so a path at or below one of
them, or a source that holds one, is refused until it starts. Where
SELinux enforces, a host directory mounted with `-v` keeps its own label, which
Expand Down Expand Up @@ -984,8 +988,9 @@ $ sudo nspawn port web
80/tcp -> [::]:8080
```

`wait NAME...` waits for machines to stop and prints each one's exit code, and
`port NAME [PORT[/PROTO]]` the ports a running machine publishes.
`wait NAME...` waits for machines to stop and prints each one's exit code once
the machine is down, as `run` exits, and `port NAME [PORT[/PROTO]]` the ports a
running machine publishes.

## rm

Expand Down Expand Up @@ -1038,8 +1043,10 @@ without flags of its own is pulled again instead of run, unless another
machine takes its network, which needs it running. What a flag cannot carry is
said in comments at the top: a secret is encrypted for this host, so
`nspawn secret create` it there first; a host directory a machine mounts has
to exist there; an image built here has to be pushed first; a healthcheck in
exec form comes back as `--health-cmd`, which runs it through `/bin/sh`, so the
image needs one. The contents of named volumes and of a machine's writable layer
stay behind, and so do the addresses nspawn handed out: volumes are seeded again
to exist there; an image made here has to be pushed first, or carried over
with `save` and `load`; a healthcheck in exec form comes back as
`--health-cmd`, which runs it through `/bin/sh`, so the image needs one. The
contents of named volumes and of a machine's writable layer stay behind
(`commit` makes an image of the writable layer, which goes the way of any image
made here), and so do the addresses nspawn handed out: volumes are seeded again
from the image, and only addresses fixed with `--ip` come along.
9 changes: 7 additions & 2 deletions content/en/docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ machines:
directory with a `mkosi.conf`, and imports the result
as a local image; `push` uploads an image to a registry, skipping the layers
that are already there. See [Building](/docs/building/).
- `save` and `load` carry images as a tar archive, without a registry; `commit`
makes an image of what a machine changed, `export` writes a machine's files as
a tar and `import` makes an image of one. See
[Images without a registry](/docs/images/#images-without-a-registry).
- The Docker Engine API, on a socket of the host (`nspawn-api.socket`) and in
each machine that mounts `/var/run/docker.sock`: the `docker` command, GitLab
Runner's docker executor and other clients make, run, attach to, exec in and
copy to and from containers, pull images and make volumes and networks, and
copy to and from, commit and export containers, pull, save, load and import
images, and make volumes and networks, and
reverse proxies that route by labels and dashboards find the machines as
containers. The server is a client of the service, as the command line is.
`auto-update` moves labelled machines to the image their tag names now. See
Expand All @@ -82,7 +87,7 @@ live in one nftables table, `ip nspawn`.

Every command is a method call on `org.nspawn.Manager`: images, machines, the
network and credentials are methods. The long operations (pull, push, build,
create, rm, images rm and prune, cp, volume rm and prune, secret rm, network rm,
save, load, import, commit, export, create, rm, images rm and prune, cp, volume rm and prune, secret rm, network rm,
connect, disconnect and prune, builder prune, auto-update) come back as job
objects that report their output and result, and `exec`, `logs`, `events` and an
attached `run` hand their streams or terminal over the bus, with a process object
Expand Down
Loading