In containers
A Containerfile, or an image from a registry, under Podman or Docker.
On this page
Moorage runs most apps directly, with a toolchain it installs. An app runs in a container when it brings its own image: a Containerfile or Dockerfile to build, or an image that is built already. It is deployed, released, rolled back, routed and logged like any other app.
The server needs Podman or Docker. No other app needs either.
From a Containerfile#
With a Containerfile or Dockerfile and no go.mod, pyproject.toml or package.json, nothing else is needed:
moor deployA language's own files come first in detection: to build the image of an app that has them, say so.
[app]
name = "guestbook"
runtime = "dockerfile"▸ detected dockerfile · Containerfile
▸ build podman build -f Containerfile .
…
▸ image localhost/moorage/guestbook:bld_01m6hrr5e7pw8bxb1jntjhx30m, 7.6 MiB in 19.2s
▸ release v1: /guestbook migrate
set up the guestbook in /data
▸ rollout web ×1
✔ live v1 https://guestbook.apps.example.com (22.1s)The engine keeps its layers, so the next build is quicker. git push works the same way. A complete app: the Guestbook example, with a multi-stage build and an image holding one binary.
Variables flagged for builds (moor env set --build) reach the build as build arguments, for the ARG lines that name them. Remember that an image's history keeps its build arguments: don't pass a secret this way to an image anyone else will see.
From an image#
moor deploy --image ghcr.io/acme/api:1.4 --app apiThe server pulls the image and records its digest. Restarts and rollbacks run exactly that image, whatever the tag has come to mean since; deploying the same tag again picks up what it means now. An image on the server only, that no registry has, is used as it is.
The moorage.toml in the current directory goes with it, if there is one, and no other file. Or name the image there, and moor deploy needs no flag:
[app]
name = "api"
runtime = "image"
[container]
image = "ghcr.io/acme/api:1.4"Private registries#
The server signs in with credentials an admin gives it, kept encrypted with its master key:
moor registry login ghcr.io --username acme-deployThe password is asked for, or read from standard input. Nothing checks it until the next pull. It reaches the engine in a temporary file, readable only by the server's user, for as long as the pull takes; it is used for private base images too. moor registry lists the registries and moor registry logout HOST removes one.
What runs#
| Command | What the image says to run. A command under [processes] replaces it, entrypoint and all. |
| Plain and shell commands | A command of plain words runs directly, so an image needs no shell for it: /app/server --port 8000. Anything else ($PORT, &&, quotes) runs in the image's /bin/sh. |
| Port | port under [container], or else the lowest port the image EXPOSEs, or else 8080. $PORT is set to it, and the app must listen on all addresses: $HOST is 0.0.0.0. |
| Publishing | On the server's loopback interface only, on a port Moorage chooses. Traffic arrives through the router. |
| User | user under [container], or else whoever the image says. |
| Data | The environment's data directory at /data, or mount under [storage], as $MOORAGE_DATA_DIR. It survives deploys. |
| Variables | [env], the app's variables and secrets, and Moorage's. Nothing else comes from the server: PATH, HOME and the rest are the image's. |
| Limits | [resources]: memory, CPU and processes, for each instance. |
| Privileges | no-new-privileges, and no host network or privileged mode. An init process reaps zombies and passes on signals. |
The release command, and on_create, run in a container of the new image, with the same variables and data directory, and no port. So do workers: every process under [processes] is a container of the same image.
[app]
runtime = "dockerfile"
[container]
port = 8000
user = "1000:1000"
[resources]
memory = "512MiB"
cpu = 1.5
[release]
command = "/app/migrate"
[processes.web]
health = { path = "/healthz" }
[processes.worker]
command = "/app/worker"Running them#
moor ps, moor logs, moor restart and moor rollback work as for any app.
- Moorage owns restarts, by
restartunder[processes]. The engine's own restart policy is off, and a container that keeps exiting is restarted more and more slowly. One the kernel killed for running out of memory says so in its log and inmoor ps --json, where the engine reports it. Podman 4.9 does not: the log says the container was killed, perhaps for going over its memory limit. - A health check needs an answer. A published port accepts connections whatever the container is doing, so a TCP check also waits to see that the connection stays open: a
health.pathis still the better check. - Containers outlive the server. A restarted server finds them by their labels and takes them over, and their output in between is in their log. After a reboot, they are started again.
- Each is a command you could run yourself. Moorage calls the engine's command line. Its containers are named
moorage-<app>-<env>-<process>-<n>-<id>and labelledio.moorage.*, sopodman ps --filter label=io.moorage.app=guestbookfinds an app's. Removing one is noticed, and the instance is replaced.
Choosing the engine#
Under [containers] in server.toml:
[containers]
engine = "auto"auto is whichever of Podman and Docker is answering, or else the first one found. Otherwise, name a binary. The engine runs as the server's user, with its usual settings: CONTAINER_HOST and DOCKER_HOST in the server's environment are honoured.
The engine#
Only an app that runs in a container needs one. The server asks as it starts, without waiting for the answer, and says what it found in its log. A server with apps in containers waits a few seconds for it, and what it cannot find out in that time waits for the engine. After that it asks when something needs the engine, such as deploying one of those apps, and when someone looks at how the server stands, keeping the answer for half a minute. An app that does not run in a container never causes it to ask.
| It finds | Means | What happens |
|---|---|---|
| Absent | No program to run | The server and every other app carry on. Deploying what needs an engine says to install one |
| Not answering | A program with no daemon or machine behind it, such as Docker Desktop not started or podman machine stopped | The same, and it says to start it |
| Ready | It answered | Apps can run in containers |
So you can start Docker Desktop an hour later, or install Podman, with no restart. A daemon that goes down does not make Moorage think that what it was running has stopped: once it answers, the same containers carry on. While it is down, deploying, restarting, scaling, rolling back, putting such an app to sleep or deleting it says why it cannot, and changes nothing. If it stops answering while apps need it, server.engine_down says so, to the rules that ask. A container that could not be stopped is stopped once the engine answers.
Once an image has been built or fetched under an engine, the server stays with that one while anything here needs it, even if another is answering, as the image is in that engine's store. Until then, it takes whichever answers.
moor server doctor and the API say how it stands too.
Good to know#
- Secrets are visible to the engine's users. A secret reaches the engine through its environment, on no command line and in no file. The container keeps it in its configuration, so anyone who can
inspectthe container can read it: on a server, that is whoever can already use the engine. - A secret cannot be called what the engine's command line uses for itself:
PATH,HOME,TMPDIR, orDOCKER_*,CONTAINER_*andXDG_*variables it reads. The deploy says so. - The data directory is writable by any user, because the image's user is whoever the image says. The directories above it keep out the server's other users. With rootless Podman, files a container's non-root user writes belong to a user of the container's, and to read them on the server you need
podman unshare. - Old images are removed with their releases, beyond
keep_releases. An image another app also uses is pulled again when it is next needed. - Metrics come later. The engine's numbers for CPU and memory arrive with metrics, in 0.5.0.