Commit Graph
298 Commits
Author SHA1 Message Date
Benedikt JohannesandGitHub 3bd0aa7160 Remove trailing comma (#1315) 2026-03-16 08:36:31 -07:00
24f6b747f1 Reap auto remove containers if there are running on system start (#1290)
This PR reaps already running containers with auto remove flag on
container system start.

Container API server shutdown ideally should stop every running
container, and reap the containers with auto remove flag. However, crash
or unexpected exit of API server leaves the containers running. In such
case, next system start should stop running containers (i.e., launchd
services) and reap the containers with auto remove flag.

## Type of Change
- [X] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
Preserve the system to be in a consistent state after unexpected
failure.

## Testing
- [X] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs

---------

Co-authored-by: Raj <realrajaryan@gmail.com>
2026-03-13 09:14:45 -07:00
ChengHao YangandGitHub 79ef8469bc Refactor: container export a tar archive (#1303)
Fixed #1265.

## Type of Change

- [ ] Bug fix
- [ ] New feature  
- [x] Breaking change
- [x] Documentation update

## Motivation and Context

Fixed #1265

## Testing

- [x] Tested locally
- [x] Added/updated tests
- [x] Added/updated docs

---------

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
2026-03-11 12:43:13 -07:00
Willjianger9andGitHub 57d89c25aa Add fallback to CONTAINER_DEFAULT_PLATFORM for image architecture (#1286)
- Closes #1252 (part of #913).
- Commands that accept `--platform` currently require it
  to be passed explicitly every time. Users working
  consistently with a non-native platform (e.g. `linux/amd64`
  on Apple Silicon) have no way to set a default, unlike
  Docker's `DOCKER_DEFAULT_PLATFORM`.
- This adds support for the `CONTAINER_DEFAULT_PLATFORM`
  environment variable as a fallback when `--platform` is not
  explicitly provided.
2026-03-06 23:38:16 -08:00
RajandGitHub 926b3a3a23 Add build.cpus and build.memory system properties (#1293) 2026-03-05 17:53:47 -08:00
jwhurandGitHub 0557b83b0e Fix race condition on SandboxService.waiters (#1289)
This PR fixes #1277.

`SandboxService.waiters` had a consistency issue (not exactly race).
`SandboxService.wait` XPC can be executed on arbitrary `id`, and it will
hang forever if no other handler resumes it. Without knowing this
internal, the high level entity can run into this issue, and deadlock.

This PR simplifies the mental model: **`SandboxService.waiters[id]:
ExitWaiter(continuations, exitCode)` can only be in three states: i)
non-existing, ii) existing with nil `exitCode`, and iii) existing with
concrete `exitCode`.**

**If it is non-existing, no handler has been registered to resume it
later. If existing with nil `exitCode`, It is guaranteed the registered
`continuations` will be resumed later with a concrete `exitCode`.
Finally, if already a concrete `exitCode`, a handler has been
registered, and already resumed (with that `exitCode`).**

Thus, `SandboxService.wait` should return immediately if `waiters[id]`
is non-existing or existing with a concrete `exitCode` (as no handler
will resume it later). It should only block when `waiters[id]` is
existing with nil `exitCode` as it is guaranteed to be resumed later. By
doing so, we can guarantee there is no deadlock at all.

For that this PR does followings:
1. Introduce `ExitMonitor` class to updates `continuations` and
`exitCode` all together atomically. Initially, `state` variable saved
the `exitCode`, but it cannot be tied with `continuations` as they are
protected by different primitives (i.e., lock and actor).
2. Gather `waiters` related operations into a single actor method,
guaranteeing those are performed atomically under actor
protection---i.e., we actually don't need Mutex here.
3. Ensure initialized `waiters` are released (i.e., resumed) later
(under any possible circumstances).
4. Move `process.wait` after `process.start` in `io.handleProcess` to
run `SandboxService.wait` only after the `waiters[id]` is initialized.

By doing fourth step, we can guarantee `SandboxService.wait` can meet
only one of two following `ExitMonitor` state: i) existing with nil
`exitCode`, or ii) existing with concrete `exitCode` (in case the
process exited too early). In both cases, `exitCode` is preserved and
returned.

## Type of Change
- [X] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
[Why is this change needed?]

## Testing
- [X] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs
2026-03-05 11:34:25 -08:00
ChengHao YangandGitHub 54e9178b40 Feat: add RegistryResource (#1195)
---------

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
Signed-off-by: ChengHao Yang
2026-03-03 21:06:01 -08:00
RajandGitHub 17503ac08d Add container.cpus and container.memory system properties (#1266) 2026-03-03 18:51:50 -08:00
RajandGitHub e0bedba81c Add mtu option for network attachments (#1267) 2026-03-03 17:57:16 -08:00
RajandGitHub 50b4c30f5a Bump Containerization to 0.26.5 (#1282)
Bump Containerization to 0.26.5
2026-03-03 11:53:33 -08:00
jwhurandGitHub 5917a60339 Fix container start hang on invalid executable (#1278)
Fix container hang when starting an invalid executable (#1277).

Ensure the `SandboxService.waiters` updated atomically, preventing a slow `wait` from registering continuation after the `SandboxService` has been stopped.

Current `ProcessIO.handleProcess` has races between `process.wait()` and
`process.start()`. In `process.wait`, `SandboxService.wait` registers
and block on a continuation so that later exit of that `LinuxContainer`
can resume it.

Even if `SandboxService.wait` checks the container state, there can be a
race so that `SandboxService.startInitProcess` fails earlier with no
continuation to resume, then `SandboxService.wait` registers the
continuation, which forever hang the thread.
2026-03-02 12:38:12 -08:00
J LoganandGitHub 6bdb647b69 Try to trigger the network privacy alert on port publish. (#1248)
## Motivation and Context
- Closes #1247.
- Hopefully better UX than waiting until clients attempt to access
published ports.
2026-02-25 14:17:09 -08:00
jwhurandGitHub 0760791ac7 Fix directory watcher (#1234)
- Current DirectoryWatcher fails if `/etc/resolver` does not exist. This
  PR fixes DirectoryWatcher to handle non-existing `/etc/resolver`
  directory. If that directory does not exist, it first watches `/etc`
  directory to check if `/etc/resolver` directory is created later. Once
  it detects new `/etc/resolver` directory, it starts watching new DNS
  resolver files there.
- This PR also fixes to log the exception thrown by API server's tasks.
- Closes #1207
2026-02-25 08:53:35 -08:00
Danny CanterandGitHub 899081d094 cli: Add --init to run/create (#1244)
Closes #1225

Add a flag to signify that we'd like to run a minimal init process that
can reap zombie processes. The actual support for this is in the
Containerization library so the plumbing here is very simple.
2026-02-23 16:02:38 -08:00
J LoganandGitHub 9f9a7c9a15 Revert "Minimal runtime variant plumbing. (#1239)" (#1255)
- This reverts commit 1942a399e3.
- This approach to getting variant into the runtime helper was fine for
proof of concept work but we need a persistent runtime config file so
that the variant is available for `container start`.
2026-02-23 13:06:27 -08:00
J LoganandGitHub 1942a399e3 Minimal runtime variant plumbing. (#1239)
- Adds plugin variant selection to bootstrap() on the Container API
service in such a way that we can revert the change soon without
compatibility issues when we work out a more permanent approach, and
requires no persistent data migration.
- Restore lexical ordering on ManagementFlags (except `--runtime`, will
take care of that next PR).
- Add a couple plugin loader tests to improve coverage.
2026-02-20 17:48:56 -08:00
Simone PanicoandGitHub c48ed09082 Fix: Environment variables can be duplicated on run (#1218)
## Type of Change
- [x] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
As reported in [1212](https://github.com/apple/container/issues/1212),
environment variables defined in a Dockerfile (ENV) were not being
overridden when passed via -e at runtime, resulting in duplicate entries
in the container's environment.

**Root cause:** `Parser.allEnv()` simply merged image, env-file, and
user-provided environment variables without deduplication. Since
`getenv()` returns the first match, the image default took precedence
over the user override.

**Fix:** `allEnv()` now deduplicates by key, with later sources
overriding earlier ones

## Testing
- [x] Tested locally
- [x] Added/updated tests
- [ ] Added/updated docs
2026-02-20 16:10:04 -08:00
J LoganandGitHub a409c0f7dd Add --format option for system status. (#1237)
- Closes #1236.
- As with other resources, default to tabular output, with `--format
json` alternative.
- Also changes common workflow to collect logs even when test step times
out.
2026-02-20 15:18:29 -08:00
Dmitry KovbaandGitHub c56d74bd3c Downgrade the mapping of warnings to the default log level (#1238)
- Upgrading warnings to error level is
  counterintuitive. Since there is no warning
  level, use default level.
2026-02-19 19:42:36 -08:00
J LoganandGitHub d29947121f CI observability enhancements. (#1193)
- Adds a a `--log-root` option to `swift system start`, propagating the
value as `CONTAINER_LOG_ROOT` to services for logging to files instead
of the OS log facility. This is not a "production" capability as it
neither merges nor rotates logs.
- Currently we don't collect logs on CI builds, and we don't have
permission to run the `log` command there. The PR adds `--log-root` to
the CI test phase, archives the results, and uploads the archive as an
artifact.
- Use FilePath from swift-system for the log root. Foundation URL is a
bit of a footgun for filesystem paths, so unless we identify a
showstopper, we should incrementally transition to this type everywhere
except where we really need network URLs.
- Output the hostname of the CI runner at the start of the test phase so
we can identify runner-specific issues where they exist.
- Fix formatting for log messages with multiple metadata items, and fix
unstructured messages on instances that weren't found using `grep -r
'log\.' Sources`.
- Adds command reference documentation for `--log-root`.
2026-02-19 17:47:41 -08:00
J LoganandGitHub 3ad0914fd2 Fix CI integration test coldstart issues. (#1230)
- Closes #1206.
- Closes #1185.
- Closes #507.
- Addresses existing log messages for #642.
- Nondeterministic CI errors are resulting from very slow launch times
for the first runtime helper, which causes ContainersService to be
locked for longer than our 20 sec timeout. Bumping the timeout to 60
seconds addresses this case for now.
- Since many log messages needed to be changed to troubleshoot the
issue, updated all log messages to use structured logging, and
implemented consistent entry/exit logging for all service operations.
- Added logging for ContainerService lock acquisition to help with
finding root cause for the slow service startup.
- Plumbed the `--debug` flag on both `container system start` and
`container system logs` so that the flag is actually useful.
- Updated the `install-init.sh` script so that can install in a custom
app root directory.
2026-02-19 09:58:09 -08:00
jwhurandGitHub d100ec9172 Support exporting current container to image (#1172)
This PR adds a command to export container to image (#1019).

## Type of Change
- [ ] Bug fix
- [X] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
Users can export their container to image.

## Testing
- [X] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs
2026-02-18 14:21:06 -08:00
Aditya RamaniandGitHub c791052741 Add init methods for all the members of the Flags type (#1203)
## Type of Change
- [ ] Bug fix
- [x] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
Authors of CLI plugins for container will be able to reuse the container
flags defined in the CLI package, instead of having to duplicate them in
their project

## Testing
- [ ] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs
2026-02-17 18:13:56 -08:00
Danny CanterandGitHub dfac83dc6b ContainerService: Add minimum memory amount validation (#1208)
Closes #1202

Today it's possible to pass a memory amount that very easily will cause
the container's VM to not be able to boot. We should protect against
this to avoid weird hangs/error messages. I could be convinced that a
limit should be in Containerization as well, but I think having one in
the daemon is a decent idea regardless.
2026-02-17 16:54:44 -08:00
Kathryn BaldaufandGitHub 5385a5c466 Support using multiple different network plugins (#1151)
## Type of Change
- [x] New feature  
- [x] Breaking change

## Motivation and Context
We want to be able to support using multiple network plugins during
`container`'s lifetime. This additionally means needing to pick an
interface strategy to interpret a network attachment based on what
network plugin was used to create that attachment. This PR will
potentially replace https://github.com/apple/container/pull/1081.

Followups:
- doc updates to include the ability to specify plugin in the network
creation cli

## Testing
- [x] Tested locally
- [x] Added/updated tests
2026-02-17 15:08:32 -08:00
AJ EmoryandGitHub 7476743cc2 feat: Moving bundle creation from ContainerService to SandboxService (#1076)
## Type of Change
- [ ] Bug fix
- [x] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
Closes #1046 -- Right now we're creating container bundles in
ContainersService. Move this to the SandboxService to make it easier to
support different container bundle types.

## Testing
- [x] Tested locally
- [x] Added/updated tests
- [ ] Added/updated docs
2026-02-13 19:27:32 -08:00
J LoganandGitHub 4c800db3fd Fix persistent CI failures. (#1205)
## Type of Change
- [x] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
- CI build is failing because runners don't have an /etc/resolver
directory, causing the directory monitor to fail. This occurs while the
install-kernel make target is running, so it appears that kernel
download is failing when it's just that the API server is dying. Created
#1207 for the issue.
- Fixing the initial scan for the directory just moves the problem to
the filesystem watch loop, likely because we're not testing the result
of `open()` for errors.
- Right now the priority is getting CI running and PRs merged, so just
commenting out the realhost DNS server setup.
- Also seeing that under some conditions it can take quite a while for
launchd to start the helper for the default network (8 seconds or more).
With the 10 second health check timeout after API server registration,
this means that some CI runs can exhibit this failure mode. Added a
`--timeout` option to SystemStart and set a 60 second timeout for
install-kernel and integration Makefile targets.
- Fixed a bug where `--debug` was being placed in the wrong location in
the api server startup args.
- Disabled all network CLI tests due to container bootstrap errors when
trying to run the container immediately after creating the network. The
slow network helper launch could be the reason behind the failures that
drove us to serialize these tests. Filed #1206 for this issue.

## Testing
- [x] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs
2026-02-13 10:51:27 -08:00
Danny CanterandGitHub f7d00aad48 APIServer: Add support for filtering to list rpc (#1175)
This is not intended to be used to support `--filter` or similar on the
CLIs list yet, it's solely to clean up our rather awkward use of
`ContainerClient.list()` today in the CLI. The list RPC simply returns
all of the containers we have created. Because of this, for a LOT of our
commands we filter to what we need client side, which feels like a
waste.. This change introduces a filter struct that we can provide an
array of container IDs, labels, and the status of the containers to
filter the `list()` output from.

This additionally, because it was killing (pun not intended) me and I
was already having to change this area for the `list()` additions,
changes container kill slightly to return an error if you try and kill a
container that doesn't exist.
2026-02-11 15:09:21 -08:00
ChengHao YangandGitHub c9f81ca332 Feat: add container registry list (#1119)
- Requires apple/containerization#502
- Closes #1088

---------

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
2026-02-10 12:26:33 -08:00
Manu SchillerandGitHub cf9b335aa1 feat: add --init-image flag for specifying custom init filesystem images per VM (#937)
- Users can now specify an alternate image to use
  with the `container run ---init-image` flag.
2026-02-09 18:11:27 -08:00
474906daf9 feat: Add runtime flag to container create and run commands (#1049) (#1109)
## Type of Change
- [ ] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
Fixes #1049 
-  Add --runtime option for Flags.Management
-  Apply runtime handler in containerConfigFromFlags
-  Update command-reference.md doc

## Testing
- [x] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs

Co-authored-by: J Logan <john_logan@apple.com>
2026-02-06 13:38:19 -08:00
Dmitry KovbaandGitHub 40de3430cd Fix relative path mount tests (#1168)
`make test` occasionally fails with:
```
✘ Test testHostDNSReinitialize() recorded an issue at HostDNSResolverTest.swift:132:45: Expectation failed: (error →    
  Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory") as? (ContainerizationError → NSError)
  ✘ Suite HostDNSResolverTest failed after 0.119 seconds with 1 issue.
```
2026-02-06 00:41:29 -08:00
aa17d46adf Warn user when a named volume is auto-created (#1108)
- Implemented the TODO at
  ContainerAPIService/Client/Utility.swift:358 — warn the
  user when a named volume is auto-created.
- This only triggers for named volumes (not anonymous
  ones), matching Docker's behavior of informing users
  about implicit resource creation.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-06 00:38:21 -08:00
J LoganandGitHub adb3c44754 Don't enable selinux LSM on boot. (#1166)
- Closes #1150.
- The problem seems to be that the selinux label attribute enforcement
doesn't play well with overlayfs.
- Solution is to set the `lsm` boot line argument. The new value
corresponds to what one would see in a Lima VM with Colima. The Kata
kernel we use doesn't provide any of those modules, so now if you run
`dmesg | grep -i lsm` in a container you will just see: `LSM:
initializing lsm=capability`
2026-02-05 20:19:13 -08:00
fabfc55568 Send tar hash in the first BuildTransfer packet (#1149)
Send the hash of entire tar file in the first BuildTransfer packet to
prevent container-builder-shim from using stale cached contents.

This PR resolves #1143.
This PR relies on apple/container-builder-shim#64.

## Type of Change
- [X] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
Current container-builder-shim uses only first few bytes of tar file as
checksum, which leads to the usage of stale cached contents if the
change of build context is not included in the first bytes of tar file.

## Testing
- [X] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs

---------

Co-authored-by: Ronit Sabhaya <ronitsabhaya75@gmail.com>
Co-authored-by: J Logan <john_logan@apple.com>
2026-02-05 09:53:31 -08:00
Danny CanterandGitHub 6e9b8d724d CLI: Forego logging errors on multi-container operations (#1163)
Instead of logging errors, and then additionally throwing an error
stating what containers couldn't be stopped/killed/deleted, let's just
concatenate the errors and throw the single error.
2026-02-05 09:47:20 -08:00
Manoj MahapatraandGitHub d79bc0d056 chore: Replace force-unwrapped String(data:encoding:) with String(decoding:as:) (#1164)
Use the non-optional String(decoding:as:) initializer for converting
JSON-encoded Data to String. This is safe for UTF-8 and eliminates force
2026-02-05 01:16:30 -08:00
Saehej KangandGitHub 21dabb74fa [build-command]: Add --pull option for fetching latest image (#844)
- Closes #733.
2026-02-05 00:13:36 -08:00
Saehej KangandGitHub 6553f9c9b7 [deps]: bump containerization to 0.25.0 (#1161)
Co-authored-by: saehejkang <saehej.kang@gmail.com>
Co-authored-by: Anthony DePasquale <anthony@depasquale.org>

- Bump `containerization` to `0.25.0`
- Updates for parameter changes on containerization
  registry access API.
- Updates for change to containerization
  `cleanUpOrphanedBlobs` function.
2026-02-04 22:16:08 -08:00
Danny CanterandGitHub 8fdfa29728 CLI: Rework ClientContainer (#1139)
ClientContainer was honestly extremely awkward. It could only be created
by passing either a ContainerConfiguration, or a Snapshot that had to be
obtained from calling a static method on the type itself. The type also
did not store a connection, so every single method got a new xpc
connection to the APIServer. This change aims to rework this type to be
just a generic client, that is *not* a client for one specific
container, but for any.

- Rename to ContainerClient
- Have list() return [ContainerSnapshot]
- Create a connection in the constructor
- Change all the callsites to use the new API
- Small, somewhat related, change to logs API in the APIServer. Now that
we don't need to call get() to grab a client anymore which was typically
what did "does this container exist" logic and gave a nice error
message, I added a small check in the APIServer to see if the container
exists and return mostly the same error message.
2026-02-04 09:52:09 -08:00
Danny CanterandGitHub 3e49dcef4e Add in missing rlimits (#1140)
Containerization didn't have these defined until a recent tag.
2026-02-03 00:45:01 -08:00
J LoganandGitHub c4c2e8515b Upgrade kernel to Kata 3.26.0. (#1134)
- Upgrade to containerization 0.24.5 to pick up zstd decompression
enhancement.
- Closes #767.
- Closes #988.
- Closes #1132.
- Requires apple/containerization#508.
2026-02-03 00:27:09 -08:00
Danny CanterandGitHub 7da25e142e Deps: Bump Containerization to 0.24.0 (#1127)
Brings in some rlimit bumps/adjustments
2026-02-02 13:35:02 -08:00
Danny CanterandGitHub 7dfe27d825 CLI: Add support for rlimits (#1129)
Closes #1097.
2026-02-02 13:30:19 -08:00
J LoganandGitHub b3b5c3e609 Use labels instead of id to discriminate the builtin network. (#1123)
- Closes #1122.
- Adds placeholder ManagedResource and unit tests. Nothing is using
these yet.
- Adds system-defined resource labels for owning plugin and resource
role. The system discriminates the builtin network using role "builtin".
- Adds builtin role when creating builtin network at startup, and
ensures that a preexisting network with ID "default" gets updated with
the role label.
- Replace all network ID checks for "default" with the builtin role
check.
- Adds "builder" role to builder VM.

## Type of Change
- [ ] Bug fix
- [x] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
Role and owner labels should make cross-cutting resource policy easier
to implement.

## Testing
- [x] Tested locally
- [x] Added/updated tests
- [ ] Added/updated docs
2026-02-02 12:24:27 -08:00
w-fergandGitHub 1dae1cdd56 Fix pfctl executable path in PacketFilter DNS reload (#1128)
## Summary

The `reload()` method in `PacketFilter.swift` references
`/sbin/reloadProcess` (the local variable name) instead of
`/sbin/pfctl`. This causes all DNS create and delete operations to fail:

```
Error: internalError: "pfctl reload exec failed: "Error Domain=NSCocoaErrorDomain Code=4 "The file "reloadProcess" doesn't exist.""
```

## Fix

One-line change: `/sbin/reloadProcess` → `/sbin/pfctl`

## Testing

Verified on macOS 26 (Tahoe) with Apple Silicon:
- `sudo container system dns create test.sdc.internal --localhost
203.0.113.1` succeeds without error
- Container can resolve and reach host services through the DNS redirect
2026-02-01 15:14:41 -08:00
Ronit SabhayaandGitHub 113a6ec5ba Fix file descriptor leak in DirectoryWatcher (#1104)
- `DirectoryWatcher` opens file descriptors for monitoring
  directories but never closes them, causing a file descriptor
  leak.
- Adds `setCancelHandler` to properly close file descriptors
  when the `DispatchSource` is cancelled.

Signed-off-by: Ronit Sabhaya <ronitsabhaya75@gmail.com>
2026-01-30 19:54:57 -08:00
RajandGitHub 3a0ad58df2 Add resource.role label to builder container (#1120)
Add resource.role label to builder container
2026-01-30 16:17:43 -08:00
J LoganandGitHub 1c01d0c411 Update to kata 3.20.0 kernel. (#1114)
- Closes #1113.
- This is the newest we can do until we address #767.
- Slight change to PacketFilter error handling so unit tests work more
reliably.
- Try making CLINetworkTests serialized to see if parallel execution is
causing flakes.
2026-01-30 11:07:49 -08:00
Danny CanterandGitHub 3f2060e460 DirectoryWatcher: Small adjustments (#1112)
- Have the handler throw
- Log the failure at error level
2026-01-29 18:25:48 -08:00