Skip to content

[Tracking]: restart policy and auto-start on boot — status of #158, #286, #1201, #1258 and a request for maintainer direction #2142

Open

Description

@huangsen365

Feature or enhancement request details

This is a tracking / status issue, not a new feature request. Everything here is already
requested and, in large part, already implemented — it is spread across two issues and two PRs,
and the work has been blocked on an unanswered maintainer decision since 2026-06-22.

Opening this to put the state in one place and ask for one specific direction call. Happy for a
maintainer to close it as a duplicate if the discussion is better held on one of the existing
threads — but please answer the question in "What we are asking for" first.

Current state

Thread What it covers State Last activity
#158 Auto-start containers on boot Open issue, unassigned 2026-02-07
#286 --restart flag on run/create Open issue, unassigned 2026-02-07
#1201 PR: --system-start flag (@saehejkang) Open, draft, paused pending direction on #1258 2026-02-24
#1258 PR: full restart policy (@JaewonHur) Open, ready for review 2026-06-22

Nothing has merged. As of today the only way to get a container back after a macOS reboot is a
user-maintained launchd agent.

What is actually blocking this

PR #1258 has a working implementation and an agreed design. It ends with a direct question to
Apple from @stephenlclarke, who maintains a fork with the work already split into three
review-sized branches:

Would Apple prefer this PR branch to be refreshed into that smaller stacked shape, or would a
new first PR for only the create-time API/CLI contract be easier to review?

That question has had no maintainer response for roughly two months. Three contributors
(@JaewonHur, @saehejkang, @stephenlclarke) are each holding off to avoid duplicating the others'
work, so the net effect is that a finished feature is idle on a review-logistics decision rather
than on a technical one.

What we are asking for

  1. A direction call on Add support for container restart policy #1258: keep the single PR, or restack it as create-time API/CLI first,
    then runtime behavior, then timing controls. Either answer unblocks it — the ambiguity is the
    blocker, not the choice.
  2. A semantics decision, which [containers]: add system-start flag for auto-start of containers #1201 is explicitly waiting on: does --restart always also
    imply start-on-container system start, or does boot behavior stay a separate
    --system-start flag? [containers]: add system-start flag for auto-start of containers #1201 is paused until this is settled.
  3. A rough signal on whether this is on the roadmap at all. If restart policy is deliberately
    out of scope for apple/container, saying so plainly is a fine outcome — it lets everyone stop
    holding branches open and lets downstream tooling commit to the launchd approach.

Field notes from running the launchd workaround

Sharing these because two of them contradict things stated earlier in these threads, and one is a
trap other users will hit.

1. container start on an already-running container is a clean no-op in 1.2.2.
The workaround in #158 carries a known-issues note that starting a running container "will stop it
and throw an error." I could not reproduce that on container 1.2.2 (Homebrew): it exits 0 and
leaves the container running. Whatever caused that appears to have been fixed. Worth knowing,
because it means a boot script does not strictly need a running/stopped filter.

2. brew services start container is actively harmful — do not recommend it.
Homebrew's plist sets KeepAlive on container system start. That command registers the services
and exits immediately, so launchd treats every exit as a crash and relaunches it in a loop.
Symptom: /opt/homebrew/var/log/container.log fills with repeated Launching container-apiserver…
lines while brew services list still reports the service as stopped. This looks like a
plausible auto-start solution and silently is not one.

3. Detecting whether the system is up needs an exact field match.
container system status prints apiserver is not running and not registered with launchd on
failure — a substring that contains running. Scripts doing container system status | grep -q running
get a false positive and skip the start. Matching the status field exactly avoids this:

container system status 2>&1 | awk '$1 == "status" && $2 == "running"'

4. A generic agent works, and survives a real reboot.
Rather than one plist per container (#158) or a label convention requiring jq (the follow-up in
#158), this enumerates every container at runtime, so containers created later are covered with no
plist edits and no dependencies beyond /bin/sh:

Boot script (POSIX sh, no dependencies)
#!/bin/sh
CONTAINER_BIN="${CONTAINER_BIN:-/opt/homebrew/bin/container}"
CONTAINER_AUTOSTART_SKIP="${CONTAINER_AUTOSTART_SKIP:-buildkit}"

log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"; }

[ -x "$CONTAINER_BIN" ] || { log "error: $CONTAINER_BIN not executable"; exit 1; }

log "starting container system services"
"$CONTAINER_BIN" system start --enable-kernel-install --timeout 60 || {
    log "error: 'container system start' failed"; exit 1; }

# 'ls -q' lists running containers, 'ls -a -q' lists all of them;
# the difference is what needs starting.
RUNNING=$("$CONTAINER_BIN" ls -q 2>/dev/null)

"$CONTAINER_BIN" ls -a -q 2>/dev/null | while IFS= read -r id; do
    [ -n "$id" ] || continue
    skip=false
    for s in $CONTAINER_AUTOSTART_SKIP; do [ "$id" = "$s" ] && skip=true; done
    $skip && { log "skip $id (excluded)"; continue; }
    printf '%s\n' "$RUNNING" | grep -qx "$id" && { log "skip $id (already running)"; continue; }
    if "$CONTAINER_BIN" start "$id" >/dev/null 2>&1; then log "started $id"; else log "FAILED to start $id"; fi
done
log "done"

Driven by a RunAtLoad=true, KeepAlive=false LaunchAgent in ~/Library/LaunchAgents.
buildkit is skipped by default since container build starts it on demand.

Verified across an actual macOS reboot, not just a launchctl kickstart: the agent fired ~30s
after boot and brought both application containers back up.

None of this is a substitute for the feature. A launchd agent cannot restart a container that
crashes while the machine is up, it has no backoff or on-failure semantics, and every user
reinvents it slightly differently — which is precisely what #286 and #1258 exist to fix.

Thanks to @JaewonHur, @saehejkang and @stephenlclarke for the implementation work already done
here, and to the maintainers for the project generally.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. saehejkang commented on Aug 19, 2026

    @saehejkang
    Contributor

    Relates to #158

    #1176

  2. Mikimoto commented on Sep 1, 2026

    @Mikimoto

    Adding a downstream data point, since this thread is asking for a direction call rather than more
    feature requests. I have no opinion on the review logistics — only on what the absence costs, and
    on what the current workaround does and does not cover.

    Use case

    A local development cluster for a data platform: 23 services under one compose file, driven through
    container-compose. Composition, with merge keys resolved:

    • 3 × etcd (DCS), 3 × Patroni/PostgreSQL, 1 × HAProxy in front of the DB
    • 1 × NATS + its HAProxy and exporter
    • 10 × observability and supporting services (OTel collector and its HAProxy, Prometheus,
      Grafana, Loki, Tempo, Alloy, pgAdmin, a monitoring HAProxy, and an LDAP server)
    • 3 × one-shot permission-fix init containers

    20 of the 23 declare restart: unless-stopped; the other 3 are the one-shot containers and declare
    restart: "no".

    What the absence actually costs

    Two distinct things, and I think the second is the one that matters more:

    Crash recovery. The failure surface is uneven. haproxy-db and nats are single instances, so
    losing either severs a whole path. etcd is a 3-node quorum, so losing one is survivable, but losing
    two makes the DCS unavailable, and Patroni then cannot renew its leader lock — the database goes
    read-only. Under Docker these come back by themselves; here they stay down until someone notices.

    Host reboot. This is the everyday cost, not the exotic one. Docker's unless-stopped brings the
    whole set back after a restart. Without an equivalent, every reboot means re-running the full up.

    What the launchd workaround does and does not cover

    Confirming the field note in the issue body, measured on container 1.0.0 / macOS 27.0:
    container start <name> on a stopped container works and returns it to running (it is
    assigned a fresh address). So a resume command that walks the project's containers and starts the
    stopped ones is straightforward to build, and that is what I plan to ship downstream.

    What it does not cover is the crash case. A resume task is externally triggered; it does not react
    to a container exiting on its own. So the workaround addresses the reboot half and leaves the crash
    half open. I mention this because "launchd covers it" is easy to read as covering both, and from a
    downstream tool's perspective it does not.

    On the direction question

    For what a downstream compose-compatible tool needs: the create-time API/CLI contract alone would
    be enough to unblock us. We need to be able to record the policy at create time and have the
    runtime honour it; the timing controls (delays, backoff, max-retries) are not on our critical path.
    So if the stacked-branch split in #1258 is the shape that gets reviewed sooner, the first branch of
    that split is already the useful one for us — we would not be waiting on the rest.

    If the answer is that restart policy is out of scope for apple/container, that is genuinely a fine
    outcome to hear stated plainly. It would let us document the gap as permanent rather than pending,
    which is a different thing to write in a README.

  3. andrew-waters commented on Sep 16, 2026

    @andrew-waters

    Another downstream data point on what the absence costs, since this thread is asking for a direction call rather than more requests.

    I maintain compose, a container compose plugin. restart: is in most real compose files, usually unless-stopped or on-failure. There is nothing in the runtime to map it onto, so my plugin has to list it as unhandled before the first run and leave it at that. There is no workaround worth shipping: supervising it from the plugin means a daemon of my own, and the plugin is not running when the failure happens.

    It affects the case people most want compose for too, a stack that survives a laptop restart. I have no view on which of #1201 or #1258 is the right shape, only that whichever direction is chosen would let downstream tools honour a key that is presently just listed as ignored.

  4. resker commented on Nov 13, 2026

    @resker

    Adding a data point on auto-start at boot, since it bears on the direction question here and on #1514, #2008 and #2058.

    The use case tested: a headless Mac where container has to come back after a reboot or power loss with nobody logged in, so a per-user launch agent isn't enough on its own.

    On current main (a release build of c05a5604, macOS 27.2.1), this works today with no code change:

    • A root LaunchDaemon with RunAtLoad runs launchctl asuser <uid> sudo -u <user> container system start --enable-kernel-install for a dedicated, never-logged-in account.
    • container registers everything in user/<uid> and starts normally.
    • A container started from the same daemon was running about a minute after power-on.
    • Tested both with and without a console user, including two boots with auto-login off and nobody logged in.

    Two things came up along the way:

    Is this an approach you'd want documented, for example a how-to with a sample daemon plist, or is a built-in way to start at boot on the roadmap? Either way, I'm glad to help with the docs or the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions