diff --git a/content/en/docs/docker-api.md b/content/en/docs/docker-api.md index 2d7a033..3d43664 100644 --- a/content/en/docs/docker-api.md +++ b/content/en/docs/docker-api.md @@ -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 diff --git a/content/en/docs/images.md b/content/en/docs/images.md index 7784a65..a3c727d 100644 --- a/content/en/docs/images.md +++ b/content/en/docs/images.md @@ -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 @@ -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 @@ -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... diff --git a/content/en/docs/machines.md b/content/en/docs/machines.md index 95a234d..5fcbce5 100644 --- a/content/en/docs/machines.md +++ b/content/en/docs/machines.md @@ -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 @@ -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 @@ -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 @@ -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. diff --git a/content/en/docs/overview.md b/content/en/docs/overview.md index 6a51e3c..7cc7f24 100644 --- a/content/en/docs/overview.md +++ b/content/en/docs/overview.md @@ -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 @@ -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 diff --git a/content/en/docs/reference.md b/content/en/docs/reference.md index 95ea023..6993d8a 100644 --- a/content/en/docs/reference.md +++ b/content/en/docs/reference.md @@ -3,7 +3,7 @@ title: Command reference linkTitle: Reference weight: 10 description: >- - Every command and option of nspawn 3.2.0. + Every command and option of nspawn 3.3.1. --- `nspawn --help` and `nspawn COMMAND --help` list the options; this page @@ -36,21 +36,21 @@ last one made of several: `busybox:1.37`, `docker.io/library/busybox:1.37` and `busybox-1.37`, the name it was pulled under, are one image to `run`, `create`, `push`, `rm`, `images rm`, `inspect`, `images inspect`, `start`, `exec`, `logs`, `network connect` and the rest. The commands that take an image, -`run`, `create`, `push`, `images rm` and `images inspect`, read a name nothing -here has as a reference too: `nspawn run busybox` and `nspawn images rm +`run`, `create`, `push`, `save`, `images rm` and `images inspect`, read a name +nothing here has as a reference too: `nspawn run busybox` and `nspawn images rm busybox` take the image of `busybox:latest`, whatever its name. The MACHINE of `cp`'s MACHINE:PATH is a name. A reference never names a machine made from the image, which has a name of its own: `rm nginx:latest` removes the image and leaves the machines made from it, and `stop nginx:latest` stops none. Where the image is only read (`inspect`, -`images inspect`, `push`), a machine made from it holds it too and is taken -when no image of it is left. A text that names nothing here is refused by the -command (a reference in full under `--registry`, when it is given): a reference -of no image here is `no local image of REFERENCE` to -`images rm`, `images inspect`, `push` and `run --pull never`, and `no machine or -image of REFERENCE` to the commands that take a machine (`rm`, `inspect`, -`stop`, `exec`, `logs` and the rest; `start` adds how to pull it). +`images inspect`, `push`, `save`), a machine made from it holds it too and is +taken when no image of it is left. A text that names nothing here is refused by +the command (a reference in full under `--registry`, when it is given): a +reference of no image here is `no local image of REFERENCE` to `images rm`, +`images inspect`, `push` and `run --pull never`, and `no machine or image of +REFERENCE` to the commands that take a machine (`rm`, `inspect`, `stop`, +`exec`, `logs` and the rest; `start` adds how to pull it). ## Global options @@ -260,6 +260,116 @@ stored for it. `IMAGE` is a local image's name or its reference (see recorded for the image. The destination needs a tag, not a digest. On a terminal a bar shows how far each blob got, as with `pull`. +## save + +```text +nspawn save IMAGE... [-o FILE] +``` + +Writes images to one tar archive, on standard output or into a file; a terminal +is refused. The archive is an OCI image layout (`oci-layout`, `index.json`, +`blobs/sha256/`) with the `manifest.json` of the Docker image archive beside it, +so that [load](#load) and `docker load` both read it. Each image goes under its +reference, its manifest, config and layers as the store keeps them: a pulled +image keeps the digests its registry gave it, and nothing is compressed again. +An image pulled by its digest alone is refused, as an archive names an image by +a tag. `IMAGE` is a local image's name or its reference (see [Names](#names)). + +| Option | Meaning | +| --- | --- | +| `-o`, `--output FILE` | Write the archive into this file rather than on standard output. | + +## load + +```text +nspawn load [-i FILE] [-q] +``` + +Adds the images of an archive `save` or `docker save` wrote, read from standard +input or from a file, plain or compressed with gzip, zstd or bzip2: an OCI image +layout, whose index names the images (from an index of several platforms, the +image of the best platform this host runs), or a Docker image archive, whose +`manifest.json` names them. A name without a registry is Docker Hub's, but for +one under the configured registry where its host has no dot or port. The whole +archive is checked before an image is installed: the blobs against their +digests, the platform, a name for every image (an image `docker save` wrote by +its ID alone has none, and is refused). Each image goes under the name its +reference gives, as `build -t` places one: an image of the same reference that +never ran gives way, and a machine or an image of another reference keeps the +name while the new image goes beside it. Prints `Loaded image: REFERENCE` for +each. + +| Option | Meaning | +| --- | --- | +| `-i`, `--input FILE` | Read the archive from this file rather than from standard input. | +| `-q`, `--quiet` | Print only the images loaded. | + +## commit + +```text +nspawn commit MACHINE REPOSITORY[:TAG] [-a AUTHOR] [-m MESSAGE] [-c INSTRUCTION]... [--pause=BOOL] +``` + +Makes an image of what a machine changed over its image: the image's layers and +one more with the changes, and the image's settings with the machine's on top +(environment, entrypoint and command when given, user, working directory, stop +signal, labels but the ones that place a machine in a compose project, +healthcheck flags, and its published ports as exposed ones). The image boots, +or runs its command, as the machine does, unless `-c` gives it another +entrypoint or command. `REPOSITORY[:TAG]` is placed as [load](#load) places an +image, and `commit` prints the image's ID. + +The new layer holds what the machine itself changed, owned as the image owns +its files whatever user namespace the machine runs in. Volumes, binds and tmpfs +stay out, and so does what nspawn and systemd-nspawn make for the machine: +`/etc/hosts`, `/etc/resolv.conf`, `/etc/hostname`, `/etc/machine-id` and +`/etc/localtime` keep the image's version, and the empty files and directories +made to mount something on, the links to `/usr` (`/sbin`, `/lib64`) an image +without them gets and the journal directory of the machine's ID are left out. +Overlay and flat machines can be committed; an mstack machine is refused, since +its root exists only inside it while it runs. A flat machine's changes are +found by comparing its whole tree with the image's layers. + +| Option | Meaning | +| --- | --- | +| `-a`, `--author AUTHOR` | The image's author. | +| `-m`, `--message MESSAGE` | The comment of the image's history entry. | +| `-c`, `--change INSTRUCTION` | A Dockerfile instruction that sets the image's settings: `CMD`, `ENTRYPOINT`, `ENV`, `EXPOSE`, `HEALTHCHECK`, `LABEL`, `ONBUILD`, `STOPSIGNAL`, `USER`, `VOLUME` or `WORKDIR`. Repeatable. | +| `-p`, `--pause[=BOOL]` | Freeze a running machine while its files are read, and thaw it after (the next start of the service does, should it end in between). Default: `true`. With `--pause=false` it runs on: what it removes meanwhile is left out, and a file whose size changes while it is read goes in at the size it had, cut or filled with zeros. | + +## export + +```text +nspawn export MACHINE [-o FILE] +``` + +Writes a machine's whole tree as a tar, on standard output or into a file, +owned as its image owns its files, without its volumes, binds and tmpfs; a +terminal is refused. A running machine runs on, as for `commit --pause=false`. +mstack machines are refused, as by `commit`. + +| Option | Meaning | +| --- | --- | +| `-o`, `--output FILE` | Write the archive into this file rather than on standard output. | + +## import + +```text +nspawn import FILE|- REPOSITORY[:TAG] [-m MESSAGE] [-c INSTRUCTION]... +``` + +Makes an image of one layer from the tar of a root filesystem, plain or +compressed with gzip, zstd or bzip2, for this host's platform, placed as +[commit](#commit) places one, and prints its ID. A tar that ends before its end +(a stream cut short) is refused. Without a `CMD` or an `ENTRYPOINT`, a machine +of it needs its command given to `run`. + +| Option | Meaning | +| --- | --- | +| `FILE\|-` | The tar archive, `-` for standard input. | +| `-m`, `--message MESSAGE` | The comment of the image's history entry. | +| `-c`, `--change INSTRUCTION` | As for [commit](#commit). | + ## images Manage local images; without a subcommand, list them. `image` is the same @@ -273,7 +383,8 @@ nspawn images [--json] ``` Lists the local images known to systemd-machined: name, type, and for the ones -nspawn installed the backend, origin (`pull`, `build` or `create`), source +nspawn installed the backend, origin (`pull`, `build`, `commit`, `load`, +`import` or `create`), source reference, size and whether the image is read-only. `--json` prints the list as the service returns it. `images list` is an alias, and `images` without a subcommand prints the same list. @@ -418,11 +529,12 @@ are not named. An image without flags of its own is pulled again instead, unless another machine takes its network. Without names it covers every machine nspawn has. What a flag cannot carry is said in comments at the top: secrets, encrypted for this host, which `nspawn secret create` makes again on -the other one; host directories a machine mounts; images built on this host, -which have to be pushed first; a healthcheck in exec form, which comes back as -`--health-cmd`. The contents of volumes and of a machine's writable layer, and -the addresses the bridge handed out, stay behind; an address fixed with `--ip` -comes along. See +the other one; host directories a machine mounts; images made on this host +(built, committed, loaded or imported), which have to be pushed first or +carried over with [save](#save) and [load](#load); a healthcheck in exec form, +which comes back as `--health-cmd`. The contents of volumes and of a machine's +writable layer, and the addresses the bridge handed out, stay behind ([commit](#commit) +makes an image of the writable layer); an address fixed with `--ip` comes along. See [The same machines on another host](/docs/machines/#the-same-machines-on-another-host). | Option | Meaning | @@ -535,7 +647,9 @@ the machine goes on should `run` be interrupted. With `--log-driver none` it comes straight from the program instead, and nothing is kept. `run` exits with the program's exit code, or 128 plus the signal nspawn sent it (130 after Ctrl-C, 137 after `kill`); a signal from elsewhere (a crash, a kill from inside, Ctrl-C with `-t`) -gives 255, or 1 for a program that is PID 1, as systemd-nspawn ends then. Ctrl-C, SIGTERM, SIGHUP and SIGQUIT are passed on to the program; a +gives 255, or 1 for a program that is PID 1, as systemd-nspawn ends then. It +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 are passed on to the program; a third Ctrl-C within a second leaves the machine running and returns. A booted image shows its console until it powers off, and Ctrl-C powers it off. @@ -691,8 +805,10 @@ read from the machine's cgroup and PID namespace. nspawn wait NAME... ``` -Waits for machines to stop and prints each one's exit code, a line per name; -a machine already stopped gives the code of its last run. +Waits for machines to stop and prints each one's exit code, a line per name, +once the machine is down: the hooks of its unit after the end are done, so `ps` +and `inspect` show it ended. A machine already stopped gives the code of its +last run. ## port @@ -713,7 +829,9 @@ nspawn cp SOURCE MACHINE:PATH Copies files and directories between the host and a machine. The machine may be running, or stopped if it is an overlay or flat -machine; a stopped mstack machine has no tree on the host until it runs. +machine; a stopped mstack machine has no tree on the host until it runs, and a +machine systemd is starting (`machinectl start`, the dependency of another +machine) is refused until it runs. - An existing directory as the destination receives the source under its own name; anything else is the name of the copy, whose parent must exist. A @@ -782,8 +900,8 @@ image their tag points to now: each is made anew with every option it had, and put back on the old image when it does not come up (healthy, with a healthcheck). Prints a table, `UNIT CONTAINER IMAGE POLICY UPDATED`, with `false`, `pending`, `true`, `failed`, `rolled back` or -`skipped`, and fails when a machine failed or went back. Built images, -references pinned by digest, `run --rm` machines, booted, flat and mstack +`skipped`, and fails when a machine failed or went back. Images made on this +host (built, committed, loaded or imported), references pinned by digest, `run --rm` machines, booted, flat and mstack machines, and machines whose image declares a volume none of their own volumes covers are `skipped`; the reason goes to standard error for a machine named on the command line, and is in `--json` always. See @@ -804,8 +922,8 @@ Reports what happens to machines, networks, volumes and secrets: for machines `start`, `die` (with its exit code), `stop`, `restart`, `oom` and `fail`, which systemd logs for every machine however it was started, `health_status` (with the new status) and what nspawn does, -`pull`, `build`, `create`, `push`, `kill`, `update`, `pause`, `unpause`, -`auto-update` and `remove`; for networks `create`, `remove`, `connect` and +`pull`, `build`, `commit`, `load`, `import`, `create`, `push`, `kill`, +`update`, `pause`, `unpause`, `auto-update` and `remove`; for networks `create`, `remove`, `connect` and `disconnect`; for volumes and secrets `create` and `remove`. It reads the journal, so past events can be read back. diff --git a/hugo.yaml b/hugo.yaml index 88e4dbc..2e9643b 100644 --- a/hugo.yaml +++ b/hugo.yaml @@ -53,7 +53,7 @@ params: privacy_policy: /about/#privacy # Version of nspawn the documentation describes. - version: 3.2.1 + version: 3.3.1 archived_version: false # In-page links to open issues and suggest changes.