App Networks

Nomatron is in early access. Some advanced workflows may not be covered in the public docs.

An app network is a named, host-local Docker network that belongs to one app. Bind app jobs to it, and Nomatron attaches their Docker tasks to that network on every eligible client. Bind several jobs to one network so they share it, or give a job a network of its own.

App networks work in every Application Networking mode, and need healthy Host Agents on the app’s cluster. Connecting the cluster is not required; app networks need only a Host Agent deployment.

Network Modes

--modeWhat you get
private (default)A Docker bridge network that Nomatron creates and owns.
internalA Docker bridge network created with Docker’s internal option, so attached containers have no outside connectivity.
existingA Docker network that already exists on the clients. Give its name with --existing-name. Nomatron uses it but never creates or deletes it.

Addressing is automatic (Docker picks the subnet) or custom with --cidr set to a canonical IPv4 or IPv6 network, such as 192.0.2.0/24. Custom ranges cannot overlap another app network’s range on the same cluster. Existing networks only accept automatic.

Nomatron-created networks are named nomatron-<network-id> on each client and labelled io.nomatron.managed=true.

Create A Network And Bind Jobs

bash
nomatron apps networks create \
  --organization acme \
  --app api \
  --name backend \
  --mode private \
  --job-slugs web,worker
  • --slug is optional; it defaults to a slug of --name.
  • Binding jobs (--job-slugs) needs the application_networks bind permission as well as permission to manage app networks.
  • A job can be bound to only one app network.

What Happens At Plan Time

When you plan a bound job, Nomatron sets each Docker task’s network_mode to the app network and records the network in the job’s metadata (nomatron.io/application-network-id), so the change is visible in the plan. On apply, Host Agents make sure the network exists on the eligible clients.

The plan is rejected if:

  • the job has no Docker tasks;
  • a task group sets a network mode other than host, or a Docker task already sets a different network_mode;
  • the job uses managed overlay networking (a job cannot use both); or
  • network validation has not passed. Validation needs healthy Host Agents with recent inventory on every eligible client.

List, Read, Update And Delete

bash
nomatron apps networks list --organization acme --app api
nomatron apps networks read --organization acme --app api --network-id <NETWORK_ID>

read prints the network as JSON, including name, mode, addressing_mode, custom_cidr, existing_network_name and job_slugs.

Update a network with apps networks update. Read the known issue below first.

Delete a network once no jobs are bound to it:

bash
nomatron apps networks delete --organization acme --app api --network-id <NETWORK_ID> --yes

Deleting a Nomatron-created network removes the Docker network from each client, and fails while containers are still attached. Deleting an existing network removes only Nomatron’s record and leaves the Docker network in place. It is also refused while containers are still attached to that network.

Known Issue: apps networks update Overwrites Settings You Do Not Pass

In Nomatron v0.1.7, nomatron apps networks update does not keep a network’s current settings for flags you leave out:

  • --name is required, even if you are not renaming the network.
  • If you leave out --mode, the network is set to private.
  • If you leave out --addressing, addressing is set to automatic and any custom CIDR is removed.
  • If you leave out --job-slugs, all jobs are unbound from the network. Because the job list is always sent, every update also needs the application_networks bind permission.

Workaround: read the network first, then pass every setting you want to keep.

  1. Read the current settings:

    bash
    nomatron apps networks read --organization acme --app api --network-id <NETWORK_ID>
  2. Run update with the current values for --name, --mode and --addressing. Add --cidr if addressing is custom, --existing-name if the mode is existing, and --job-slugs with every job that should stay bound:

    bash
    nomatron apps networks update \
      --organization acme \
      --app api \
      --network-id <NETWORK_ID> \
      --name backend \
      --mode private \
      --addressing automatic \
      --job-slugs web,worker
  3. Run read again and check that mode, addressing_mode, custom_cidr and job_slugs are what you expect.

Leave out --job-slugs only if no jobs should be bound to the network.

In v0.1.7, a change to the mode or addressing of a network that already exists on clients is not applied in place, and the next deployment fails on those clients. To change either one, create a new app network, move the job bindings to it, then delete the old network.

Alternatively, use the API. A PATCH request keeps every field you leave out, including job bindings:

bash
curl --fail -X PATCH \
  "$NOMATRON_ADDR/api/v1/organizations/acme/apps/api/networks/<NETWORK_ID>" \
  -H "Authorization: Bearer $NOMATRON_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{"name":"backend-v2"}'

The request body uses name, mode, addressing (an object with mode and cidr), existing_network_name and job_slugs. These names differ from the fields that read prints. To change custom addressing, send addressing.mode and addressing.cidr together.