The app file
nk/app.yaml is the compose file Nikasa starts your app from. nk init drafts it from what your repository has, and says what it inferred, guessed and found missing.
On this page
- What the app file needs
- An example app file
- Nikasa's settings under x-nk
- Your env file
- Missing settings
- What nk try tells you
- What nk init prints
- When nk init asks a question
- Where nk init looks for your app
- How nk init picks the app
- How nk init finds the port
- What nk init changes for the sandbox
- The app's health check
- Identity provider settings
- Keycloak
- Related pages
The app file, nk/app.yaml, tells Nikasa how to start your app and the services it needs.
Most people let nk init draft it, and then check two things: the app and its port. nk try then tells you what is wrong, if anything. This page explains what the file holds and how the draft is made, for when you need to change it.
To make your first draft, follow Get started.
What the app file needs #
The app file is a Docker Compose file with:
- a service named
appwhoseimageis${NK_IMAGE}, with a health check that Nikasa waits for. Nikasa setsNK_IMAGEto the image of the build it is running. - any services your app depends on, such as databases and brokers.
An example app file #
Here is a small app file, written by hand, for an app that uses Postgres:
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: myapp
POSTGRES_USER: myapp
POSTGRES_PASSWORD: myapp
tmpfs:
- /var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U myapp -d myapp"]
interval: 1s
timeout: 3s
retries: 30
depends_on:
capture:
condition: service_healthy
app:
image: ${NK_IMAGE}
environment:
DATABASE_URL: postgres://myapp:myapp@postgres:5432/myapp
healthcheck:
# Hand-written: this runs a binary from your image. The check nk init drafts brings its own busybox, so it needs none.
test: ["CMD", "/myapp", "-health", "http://127.0.0.1:8000/health"]
interval: 1h # once the app is up, check rarely
start_period: 60s # failures in the first minute do not count against it
start_interval: 1s # and in that minute, check every second
timeout: 3s
depends_on:
capture:
condition: service_healthy
postgres:
condition: service_healthyYou do not define capture, the container that records the network. Nikasa adds it when it starts the project, and every service waits for it, as shown. So this file runs only through Nikasa.
nk demo leaves a working example in nk-demo/sample.
Use a compose file you already have #
A compose file already made for Nikasa is not drafted again. Give it to --app as it is.
If your project has compose files of its own that this one builds on, nk compare --with <file> loads them first.
Nikasa's settings under x-nk #
x-nk: is a block in nk/app.yaml that holds Nikasa's own settings. Docker Compose ignores any top-level key that starts with x-.
x-nk:
host: http://app:8000
env_file: ../.env| Key | What it does | More |
|---|---|---|
host |
The address requests go to. The default is http://. |
A path in host |
env_file |
The env file your compose file reads, or a list of them. | Your env file |
tests |
The suite nk record runs, and what it needs. |
The tests block |
outside |
The only hosts allowed to leave the sandbox. | Outside services |
tracker, tracker_kind |
Where ticket links open. | Tickets from a report |
baseline_store |
Where saved baselines are kept. | Baseline storage |
A path in host #
host may hold a path, such as http://app:9966/shop:
- Your own
.hurlfiles get it whole, as{{host}}. - The recorded steps of a pack are sent to the address without the path, since their paths already hold it.
A pack is a folder holding a recorded session, which Nikasa sends again to both builds. See Words in a report.
The tests block #
The tests block says where your suite is and what it needs. Its keys are driver, folder, setup, args and env. For example:
x-nk:
tests:
driver: playwright # or cypress, newman, bruno
folder: e2e # where the suite is, from where you run nk record
env:
E2E_PASSWORD: ${E2E_PASSWORD} # taken from the environment of the machine that runs nk recordGive your tests what they need lists every key.
Your env file #
Nikasa reads the configuration your team already runs the app with, from where Compose and your CI already look for it. It never copies your env file, so nk/ never holds a copy.
How it is recorded #
nk init records the env file as one line under x-nk::
x-nk:
env_file: ../docker/.envThe path starts from the app file's folder, nk/, the same way Compose reads a service's env_file:. So ../docker/.env is the file at docker/.env in your repository.
To read more than one file, give a list. Later files win:
x-nk:
env_file: [../.env, ../.env.nk]How Nikasa finds the file #
Compose looks for a .env in the compose file's folder. nk init records that file when the compose file does any of these:
- reads a variable, as
${VAR}or$VAR; - lists an environment entry with no value, as
- NAME; - has a service that names that
.envunderenv_file:.
An escaped $$, or text after a #, does not count.
To record other files instead, name them. Give the flag as often as you need. Later files win:
nk init --env-file docker/.env --env-file docker/.env.localA file that does not exist yet is skipped, and the first line of each command says so.
When nk init drafts from a GitHub Actions job, it records an env file only when the job reads one itself. That is when a step of the job does any of these:
- copies or writes an env file;
- names one;
- mentions
NK_ENV_FILE; - runs Compose.
NK_ENV_FILE is the name that nk init --ci gives the secret it writes an env file from.
How the commands read it #
nk try, nk run, nk record and nk compare pass each recorded file that exists to Compose with --env-file, the way docker compose up reads one.
They read a recorded path from the app file's folder, wherever you run nk. So a recording made from the old build's checkout finds the same file.
The first line each command prints says which env file it read, before anything starts. When the file is under the folder you run nk in, the line writes its path from that folder, as docker/.env:
| First line | What it means |
|---|---|
using nk/ |
It read ., which holds 7 settings. |
using nk/ |
The app file records ., but the file is not there. |
using nk/ |
It also read app., a file a service reads whole under env_file:. Each such file is named once, after the recorded ones. |
Use another file for one command #
The same flag on those commands replaces the recorded files, for that command only:
nk try --env-file test-keys.env myapp:oldIts path starts from the folder you run nk in, as Compose's own flag does. Env file paths lists where each kind of path starts.
Variables in your shell win over every file, as in Compose. That is how a CI job gives values with no file.
What goes into nk/app.yaml #
None of your env file's values go into nk/app.yaml. There are two exceptions, when your compose file takes them from the env file: a health check's port and a mount's folder. The printout names each one by its setting:
the health check's port 3000 is PORT from .env
a mount's folder ../kept is KEPT_PATH from .envA service's own env_file: keeps pointing at your file, as ../docker/.env. If that file is not there yet, it is read once it is.
Files a service reads itself #
Any other file a service names under env_file:, such as app.env, stays with that service:
- Nikasa reads it for the
config:line, and names it in the first line of a command. - Nikasa never hands it to Compose as
--env-file, since Compose fills no variable from it. - A setting in it counts as set when Nikasa checks the example file's keys. It does not count for a variable the compose file reads, which still needs a recorded file or your environment.
The config: line names the recorded files first, then the service's own:
config: .env does not exist yet and app.env read, 3 settings; 2 to provide (SITE_URL, APP_TRUSTED_HEADERS); nk/init.txt lists each with its commentMissing settings #
nk init names, by setting, anything your configuration lacks. It makes no value up.
The config line #
nk init prints one line that says which files it read and what you need to provide:
config: .env read, 7 settings; 2 to provide (APP_SECRET, SITE_ROOT); 65 optional, a value switches the feature on; nk/init.txt lists each with its commentThe line is the files read, then up to three parts, separated by ;:
| Part | Example | When it shows |
|---|---|---|
| The files read | . or . |
Always. |
| To provide | 2 to provide (APP_SECRET, SITE_ROOT) |
Some settings need a value. The line names 8 at most. |
| Optional | 65 optional, a value switches the feature on |
Some keys name an outside service. |
| Left empty | 41 left empty as in the example |
Your file leaves keys empty, as the example file does. |
nothing to provide takes the place of the second part when keys are left empty and none must be provided.
When there is nothing to name, the line is one part ending , nothing missing:
config: .env read, 7 settings, nothing missingWith no file and nothing missing, there is no config: line.
What counts as missing #
The settings to provide are listed in this order:
- Settings the compose file reads with no value, which no recorded file and no variable gives.
- Keys an example env file leaves empty, or holding a placeholder, which no file read holds.
An example env file is a file beside the compose file, or at the root, with env in its name and example, sample, dist or template. For instance, .env.example or .env.sample.
A key whose name says an outside service is counted as optional, not listed to provide. That is a name ending in _API_KEY, _CLIENT_SECRET, _ACCESS_TOKEN, _LICENSE_KEY or _PRIVATE_KEY, or holding a vendor's name.
A key the example gives a value is never listed.
The notes in nk/init.txt #
nk/init.txt lists each setting with what the example file says of it. For the .env.example in Get started, its config: section reads:
config:
.env does not exist yet; 2 to provide (APP_SECRET, SITE_ROOT)
APP_SECRET: to provide, docker-compose.yml reads it with no value; the example says: 32 random characters
SITE_ROOT: to provide, docker-compose.yml reads it with no valueKeys your file leaves empty #
Your own file may list a key with no value, where the example file leaves it empty too. That key is not named for you to provide. It becomes one count instead:
config: docker/.env read, 86 settings; nothing to provide; 41 left empty as in the example; nk/init.txt lists each with its commentas in the exampleappears only when the example file leaves every one of those keys empty too.nothing to provideappears only when keys are left empty and none must be provided.nk/init.txtnames each key, its file, and what the example says of it.
When the env file does not exist yet #
The next: line starts with the step that creates the file, taken from the example file:
next: cp .env.example .env and fill APP_SECRET, SITE_ROOT, then docker build -t myapp:old . && nk try myapp:oldWith no example file, the step reads put APP_SECRET, SITE_ROOT in .env. No other line repeats this step.
No setting is filled in for you. With --yes, with CI set, or with no terminal, nk init lists the same settings, fills none of them, and still writes the draft.
Placeholders #
A template's placeholder, such as changethis, change_me or <your-key>, is named, never replaced. Nikasa names it wherever it finds it: in the compose file, in a default, or in your env file. The line says where to set a real value:
APP_SECRET in docker-compose.yml is the template's placeholder: the app may refuse it; set it under environment: in nk/app.yamlA password that a database leaves empty is named too, since its image refuses to start on it. A database told to take none, with a trust auth method or ALLOW_EMPTY_PASSWORD, keeps it empty.
localhost in your file #
In the sandbox, localhost is the app's own container. So a setting that points at localhost is named with the service that listens on that port:
.env points DATABASE_URL at localhost, which in the sandbox is the app's own container: use `db` there instead, under environment: of the app in nk/app.yaml or in a second file listed under x-nk: env_fileImage tags from a variable #
When an image's tag comes from a variable that nothing sets, nk init looks for a shell script beside the compose file, or at the repository's root. If the script says what the tag is, nk init uses it.
- It reads the script as text, and runs nothing.
- It never takes the tag from an env file.
Otherwise the tag is named as missing. A run with no tag for an image stops at once and names the variable.
Missing lines #
Missing lines in the printout name what only you can supply:
- settings that a workflow's job fills in when it runs, as the next section shows;
- an env file a service reads that does not exist yet.
A missing line is left out when another line already says the same:
- the line about the env file that does not exist, when
next:already says to copy it from its example; - the example's empty keys, which the
config:line counts.
A line saying the example points a setting at localhost stays.
One other kind of missing line names mounted scripts with Windows line endings, which a Linux container cannot run. That is a fix for you to make, with the git setting the line gives, not a value to supply.
Settings a CI job fills in #
A setting that a job's env: fills from a ${{ ... }} expression has no value until the job runs. That covers a matrix value, such as ADAPTER: ${{ matrix.db }}, a secret, or one of GitHub's own variables.
A draft from a GitHub Actions job names them once, and drafts each as NAME: ${NAME}:
set by GitHub when the job runs: ADAPTER; set it in your environment or under environment: in nk/app.yaml, if the app needs it- A job that reads no env file records none, and lists no keys from an example file.
- When the job reads one itself, the line says
set it in .env, which nk/app.yaml reads as x-nk: env_file, or in your environmentinstead.
What nk try tells you #
nk try starts the draft once, before any compare, with no second attempt.
How long a start waits #
A start waits until the app is healthy, until it exits, or until the health check gives up:
- The health check that
nk initdrafts asks every 2 seconds, and gives up after 60 failed tries. - Whatever the health check says, a start never waits more than 10 minutes. That limit is Docker Compose's wait. It is fixed, and the same in
nk tryand in every run of a compare.
A start, in a try and in every run, also ends early when the app has settled on another port. That is when all of these are true:
- the port its health check asks is closed, and another is open;
- its ports and last log line have not changed for 2 minutes;
- its container is idle;
- no other service is still starting.
nk try writes its run folder to out/try, unless you give a folder after the image:
nk try myapp:old out/try-mainWhat it says #
| What happened | What it prints | Exit status |
|---|---|---|
| Healthy | The outside hosts it reached, nothing to change in nk/, and the compare to run next. |
0 |
| The app exited | Its last 5 log lines. If a line names a setting that no env file and no variable gives, it also names the setting and your env file, as APP_SECRET is not set: .. If the app's own env_file: leaves the setting empty, it names that file instead. |
2 |
| The app never started | the app never started, as what it waits for did not, so it logged nothing. A service the app waits for never started, so the app itself logged nothing. This line takes the place of the app's last log lines, which would read (it logged nothing). |
2 |
| A service asks for a setting | The setting, in capitals, that the service says must be set, and where to put it: under environment: of that service in nk/, or in the env file the draft gives it. |
2 |
| A service lacks its command | The services, and the program they lack. A compose file made to run a build image can start services with a tool such as make, which a release image does not hold. You can remove their command: and any source folder mounted over the image, so the image's own start runs. Or you can give nk an image built the way the compose file builds it. |
2 |
| A one-shot job finished | The service is named, and the start goes on waiting for the rest without running it again. This is a service other than the app that exits 0 while the sandbox starts, such as a migration that nothing waits for. A service that exits with an error, or that another service waits for as healthy, still stops the start. | The start goes on |
| The app exited 0 before it was healthy | the app ended by itself. The image probably needs a command: under app. |
2 |
The app tried localhost |
localhost is the app's own container here; use <service>:<port> |
2 |
| It never got healthy | The cause, then the same log lines. | 2 |
| It listens on another port | With one such port, and if you have not edited the file, it corrects x-nk: host and the health check in nk/, and keeps the old file as nk/. With two or more, it lists them and names nk init --port <n>. |
2 |
| It listens only on loopback | make it listen on 0.0.0.0, as the driver runs in another container and cannot reach it. |
2 |
A failed try ends with next:, which names the edit to make, and then nk try again.
What nk init prints #
nk init path/to/your/repoIt prints at most 15 lines:
app: `myapp`, built from the repository
port: 8000, from the compose file
beside it: postgres (PostgreSQL)
nk/app.yaml drafted from docker-compose.yml
notes: nk/init.txt, all 25 lines of what nk init inferred, guessed and found missing
next: docker build -t myapp:old . && nk try myapp:oldThe lines come in this order:
- The app, and why.
- The port, and why. A port that nothing gave is marked
guessed, and so is an app chosen among several. - The services beside the app.
- The
config:line, when there is something to say: the env file read and the settings to provide. See The config line. - At most 3 gaps, the most pressing first.
- The file written.
- The notes file, with how many lines it holds, as
all 25 lines of what nk init inferred, guessed and found missing. When more gaps were found than the 3 shown, it adds how many more are in it, as(3 more gaps there). next:, with one command to run. When the env file does not exist yet, it starts with the step that creates it, taken from the example file. The gaps above do not say the same step again.
nk init writes nk/app.yaml, never over an earlier one, and never edits your files.
The notes file #
nk/init.txt holds everything nk init inferred, guessed and found missing. --verbose prints all of that instead. It has a section for each kind:
| Section | What it lists |
|---|---|
recognised: |
Each service beside the app, and what Nikasa takes it to be. |
inferred: |
What it worked out from your files. |
guessed: |
What it guessed, for you to check. |
missing: |
What only you can supply. See Missing lines. |
config: |
The env files read, and each setting to provide with what the example says of it. |
asked: |
The questions it asked, and the answers. |
next: |
The command to run next, then how to build, record and compare. |
When nk init asks a question #
nk init asks at most three questions. It asks each one only when there is more than one candidate, and each depends on the answer before it.
| Question | Asked when | Answer it ahead with |
|---|---|---|
| Which compose file | More than one compose file could be the one. | --from <file> |
| Which service is the app | More than one service could be the app. | --service <name> |
| Which port the app listens on | The places that name a port name different ones. | --port <n> |
Each flag answers its own question, and skips only that one.
On a terminal, each question is a numbered list, best first:
more than one service could be your app:
1) alpha built here; health check on 3011
2) beta built here; health check on 3022
which is your app? [1]Press Enter to take the first choice, or type a number or a name to pick one.
Where a port can be named #
The port question comes only when these places name different ports:
- the compose file's
portsandexpose; - the app's environment;
- its health check;
- a proxy label;
- the Dockerfile's or the image's
EXPOSE.
When no source names a port, or all of them name the same one, nk init asks nothing. With none, the draft says port: 8000, guessed, and nk try reads the port the app really listens on and corrects the draft.
A published image that could be the app #
Your repository may have a Dockerfile at the root, while the compose file has a service on a published image that could be the app as well. Then nk init asks which of the two is the app.
- The service could be the app if it listens on a port that the Dockerfile's
EXPOSEnames. - With no port to compare, it could be the app if it waits for a database, or is the only service in the file.
The choices are app, built from the root Dockerfile, first, then that service.
--service app builds the root Dockerfile as the app, beside the file's services, when the file has no service of that name. It is refused when the repository's own name already names an image in the file.
With --yes, or with no terminal #
--yes takes the first choice of each question, and the printout says each was guessed. For a published image that could be the app, that means the build is the app, and the service stays beside it.
With no terminal, or with CI set, nk init reads nothing and writes no draft. It exits 2 with the same list and the exact command for each choice, and ends with this line:
nothing was written, as there is no terminal to ask on: run the command of one choice, or add --yes to take the first choice of each question--yes drafts there too.
Where nk init looks for your app #
nk init drafts from the first of these that it finds:
- A compose file with a service built from the repository.
- A compose file that runs the repository's own published image.
- The GitHub Actions job with the most
services:. - A compose file of services, beside a Dockerfile at the root. The app is drafted from that Dockerfile.
The repository's own image #
The repository's own image is the one named after the repository.
When no image is, it is the one that a project manifest at the root names, since a renamed copy keeps its manifest. The manifests it reads are package.json, composer.json, pyproject.toml, setup.py, pom.xml, settings.gradle, go.mod and Cargo.toml.
An image Nikasa knows as a store or a tool is never the repository's own.
Which compose file comes first #
nk init searches for compose files two folders down, and leaves out dev containers. When it finds several:
- A file whose app actually serves comes before one that only runs tests.
- Among those, a file made for CI or tests comes first. Then the usual
docker-compose.yml, then the other usual names, then the others, then a developer's setup, and override files last.
If the line nk/app.yaml drafted from <file> names a file you did not expect, give nk init --from <file> the one you mean. The printout lists the others it found.
When it finds no source #
nk init writes nothing and exits 2. It says what it did find, such as a Dockerfile, a published image that the README or workflows name, or a dev container file. Its last line is one command to try:
| Command | What it does |
|---|---|
nk init --image <ref> [--port <n>] |
Drafts the app alone from an image. If it needs a database, add it to nk/, or draft with --from. |
nk init --from <compose-file> --app-dockerfile <path> |
Drafts the app from that Dockerfile, beside the services of the file. |
nk init --from compose. |
Merges a setup split over files, as docker compose -f would. |
How nk init picks the app #
The app becomes the service app, running ${NK_IMAGE}. The service's old name stays as a network alias, so other services that reach it by that name still do.
When several services could be the app, nk init ranks them:
- One named like the repository comes first.
- Then one that publishes a port, talks to a database, has a health check of its own, or has a Traefik label routing to it.
Some services are never the app:
- a service built as a database or a search engine;
- a reverse proxy, when a service it waits for could be the app.
To pick another, use nk init --service <name>.
Other services built from your code #
Other services built from the same Dockerfile run the same build.
A service built from another Dockerfile is kept when its image: is on the app's release. That means it uses the same tag variable as the app's image, or the same registry namespace and tag. Otherwise it is left out and named, so you can give it images with --image.
A service kept on the app's release runs at the same tag as the app's image. The draft writes ${NK_TAG} for it, which each run sets to the tag of the build it starts:
worker:
image: ghcr.io/acme/worker:${NK_TAG}So build and push your other images with that tag.
How nk init finds the port #
It looks in these places, in this order:
- Published ports.
expose.- A port that the app's environment sets.
- The port in the app's own health check.
- A Traefik label.
- The Dockerfile's or the image's
EXPOSE.
The health check comes after the other ports, so a management port never wins over a published one. --port <n> names the port instead.
The address is written as x-nk: host.
If the app answers FastCGI (php-fpm), Nikasa calls it through the web server in front of it, as long as your repository's configuration passes requests to the app.
What nk init changes for the sandbox #
The draft starts from your compose file. nk init changes it to run in the sandbox:
| Change | What changes, and why |
|---|---|
| Removed | Published ports, container names, restart policies and profiles:. Also the source tree mounted over the app, which would hide the build being compared. |
| Started fresh | A database's data, and any mounted folder the repository does not hold, are kept on a RAM disk that any user can write to. Named volumes stay, and are fresh in every run too. |
| Pinned | Images on a moving tag such as latest, for the services around the app. They are pinned to the digest your Docker has, so later compares run the same image. |
| Dropped | The Docker socket. A service holding it starts containers outside the sandbox, which Nikasa neither records nor removes. nk init --docker-socket keeps it, to compare features that run containers. |
| Checked | The draft is checked against what Docker Compose refuses. A draft that fails is not written, and nk init names each problem. |
| Not applied | The override file beside the compose file: compose. or docker-compose., and their . forms. See below. |
Why the override file is left out #
Compose merges the override file into a plain docker compose up. But it usually switches on development mode, and Nikasa compares your image as it ships.
What the override file sets on the app is printed, so you can add what the image needs to start.
Services Nikasa recognises #
Recognised components get a health check that works with their image: Postgres, MySQL, MariaDB, Mongo, Redis, Valkey, RabbitMQ, Kafka, Elasticsearch, MinIO, Keycloak and more.
Anything else is named as unknown, never guessed silently.
The app's health check #
The health check that nk init drafts for the app asks the app's port for any HTTP answer:
- It uses a small static busybox that Nikasa brings in and mounts read-only, so your image needs no curl or wget.
- It sends one request and never follows a redirect. So an app that answers
302to/counts as up.
The app's own check is printed, so you can put it back.
Identity provider settings #
Your app may trust an outside identity provider for logins. When a service's environment names that provider in a setting that holds a URL (an OpenID issuer), nk init rewrites the setting to ${NK_ISSUER:-<that URL>}.
So this setting in your compose file:
environment:
OIDC_ISSUER: https://idp.example/realms/shopis drafted as:
environment:
OIDC_ISSUER: ${NK_ISSUER:-https://idp.example/realms/shop}A compare can then stand in for the provider, with an issuer of its own in the sandbox.
A setting that holds only a host name is left as it is, so the compare does not stand in through it. Edit it yourself if your app needs that, as that page shows.
Keycloak #
A Keycloak in the sandbox starts empty. So its realm is imported from the realm files in your repository, in every run, and the printout lists each file.
Export a realm with this command, which keeps secrets, users and their password hashes:
kc.sh export --realm <name> --file <name>.jsonTwo files that hold the same realm are refused too.
A file in a test folder never stops a draft. A test folder is a path with a word like e2e, tests, cypress or fixtures.
- Such a file gives way to a file outside those folders that holds the same realm.
- When only test files hold the realm twice, or its secrets are masked, it is left out, and the printout says so.
A realm file added later needs nk init again.
Related pages #
- Get started: draft your first app file and check that it starts.
- Commands: every
nk initflag. - Outside services: which hosts your app may reach, and the
outsidesetting. - Record your tests: what goes in the
testsblock. - When something goes wrong: what to do when a start fails.
Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.