Deploy container¶
In this tutorial, you'll preview and deploy a single container with syslet and check it runs under systemd.
Then you'll change it, preview the change with --diff, apply it, and confirm re-applying an unchanged spec does nothing.
Prerequisites¶
- A server with syslet installed, as in Installation.
1. Write a container spec¶
Create a file named webapp.json:
| webapp.json | |
|---|---|
unit.Container maps directly onto the [Container] section of a quadlet .container file.
syslet sets ContainerName to webapp, the spec's name.
2. Preview the deployment¶
Pipe the spec to syslet on the server over SSH, with --diff:
| Bash | |
|---|---|
--diff runs the full plan (validate, diff against installed state) but stops before executing anything.
It shows the unit file syslet would write, including the options it adds on its own, and that the container would be started:
Nothing on the server is touched yet.
3. Apply it¶
Run the same command without --diff:
| Bash | |
|---|---|
syslet reads the spec, validates it, generates /etc/containers/systemd/webapp.container, runs systemctl daemon-reload, and starts the container.
It logs each action as it runs, then prints the result per unit:
It also saves the applied spec to /etc/syslet/config.json.
4. Verify¶
You should see webapp.service active and a running nginx container.
Because desiredState: "running" was set, syslet also added Restart=always and WantedBy=multi-user.target default.target, so the container restarts on crash and starts on boot.
The RestartSec, RestartSteps, RestartMaxDelaySec and StartLimitIntervalSec defaults make systemd wait longer after each crash, up to five minutes, instead of giving up after five quick failures.
On a systemd older than 254 you see RestartSec=10s instead, without RestartSteps and RestartMaxDelaySec (see Set systemd service options).
5. Preview a change¶
Edit webapp.json to publish an extra port:
| webapp.json | |
|---|---|
Preview it again:
| Bash | |
|---|---|
This time the plan diffs against the installed unit, so it only shows the new option, and that the container will be stopped and started again:
| Text Only | |
|---|---|
Nothing on the server is touched yet.
6. Apply it¶
| Bash | |
|---|---|
syslet carries out the plan it just showed:
7. Re-apply without changes¶
Run the exact same command again:
| Bash | |
|---|---|
syslet reports no changes and does not stop or restart webapp.service:
| Text Only | |
|---|---|
Applying an unchanged spec is always a no-op, which makes it safe to re-run syslet on every deploy, or on a schedule, without unnecessary restarts.
See Deploy over SSH for more on this workflow. Continue with Setup CUE repository.