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 deploy

A 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 api

The 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-deploy

The 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#

CommandWhat the image says to run. A command under [processes] replaces it, entrypoint and all.
Plain and shell commandsA 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.
Portport 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.
PublishingOn the server's loopback interface only, on a port Moorage chooses. Traffic arrives through the router.
Useruser under [container], or else whoever the image says.
DataThe 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.
Privilegesno-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.

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 findsMeansWhat happens
AbsentNo program to runThe server and every other app carry on. Deploying what needs an engine says to install one
Not answeringA program with no daemon or machine behind it, such as Docker Desktop not started or podman machine stoppedThe same, and it says to start it
ReadyIt answeredApps 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#

Suggest a change to this page