Commit Graph

279 Commits

Author SHA1 Message Date
J Logan 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 Logan 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
jwhur 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 Ramani 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 Canter 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 Baldauf 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 Emory 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 Logan 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 Canter 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 Yang 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 Schiller 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
Amir Alperin 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 Kovba 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
Poetry Of Code 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 Logan 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
jwhur 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 Canter 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 Mahapatra 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 Kang 21dabb74fa [build-command]: Add --pull option for fetching latest image (#844)
- Closes #733.
2026-02-05 00:13:36 -08:00
Saehej Kang 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 Canter 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 Canter 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 Logan 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 Canter 7da25e142e Deps: Bump Containerization to 0.24.0 (#1127)
Brings in some rlimit bumps/adjustments
2026-02-02 13:35:02 -08:00
Danny Canter 7dfe27d825 CLI: Add support for rlimits (#1129)
Closes #1097.
2026-02-02 13:30:19 -08:00
J Logan 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-ferg 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 Sabhaya 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
Raj 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 Logan 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 Canter 3f2060e460 DirectoryWatcher: Small adjustments (#1112)
- Have the handler throw
- Log the failure at error level
2026-01-29 18:25:48 -08:00
Danny Canter 0a7fb07757 Set mtu to old Containerization default (#1110)
The old mtu default in containerization was 1280 to account for some
alpine/musl images that have issues with
1500. This changed in the last couple tags to be modifiable, but the new
default is the standard 1500. Ideally we eventually allow supplying the
mtu to be used when you create a network (or possibly a container
creation setting), but for now just default in here back to what CZ used
to use.
2026-01-29 14:21:12 -08:00
jwhur d762fe55a2 Launch a service with waitForDebugger if specified (#1101)
This PR enables launching a service with `waitForDebugger` flag if the
service label matches a given env variable `CONTAINER_DEBUG`.
2026-01-28 18:22:33 -08:00
J Logan d8722708ec Removes ArgumentParser import from NetworkMode. (#1102)
- ContainerResources shouldn't need to know anything about CLI stuff.
- Move ExpressibleByArgument protocol conformance to an extension in the
package where it's needed.
2026-01-28 09:04:58 -08:00
Saehej Kang 3abf81f69e [image-list]: Add full size field to json output (#1098)
- Refer to #862
- Updated `SIZE` field to `FULL SIZE`, as it seemed more appropriate so
it does not get mixed up with the `descriptor size` field
- Closes #860
2026-01-27 20:00:43 -08:00
ChengHao Yang 24cbed56b3 Implement container prune (#904)
- Fixed #892.
- By contrast with `rm`, `prune` should display
  the amount of reclaimed storage, so added code
  to retrieve it.

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
2026-01-27 14:55:49 -08:00
jwhur a57527e4b0 Refactor container lifecycle functions to perform scoped rollback on failure (#1080)
- Closes #977.
- Closes #1058.
- Prevents unexpected removal of containers on
  bootstrapping and starting failures, by reorganizing
  error handling for container `run`, `start`, and
  `exec` so that error handling only unwinds that
  which was done in the current scope.
- Relies on apple/containerization#495.
2026-01-27 11:15:22 -08:00
jwhur 9d4cdede8c Isolated network (#1079)
- Closes #1037.
- Adds a `--mode` flag that has `nat` and `hostOnly` options.
  The host-only option selects the vmnet host-only mode,
  where containers attached to the network can reach each
  other and the host, but not external systems.
2026-01-26 19:35:41 -08:00
ChengHao Yang b371aee610 Feat: container image delete force option (#1096)
- Fixed #1087

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
2026-01-26 13:07:05 -08:00
jwhur ed1185d489 Container-to-host networking. (#1078)
- Closes #346.
- This PR enables connecting host's localhost ports from
  containers.
- It adds an option `--localhost <localhost>` to DNS
  create command, after which the packets heading
  ip address in container are redirected to localhost in
  host machine. Packet filter rule is added and deleted
  along with the creation and deletion of localhost domain.
2026-01-23 17:59:28 -08:00
Stanislav Antonichev 751c1fc05c Add --dns support to build command for custom DNS resolution (#1067)
This change adds --dns parameter support to the build command, matching
the existing functionality in the run command. This allows users to
specify custom DNS nameservers (like Google DNS 8.8.8.8) when building
container images, which is essential when the host machine uses a local
DNS resolver (e.g., 127.0.0.2) that doesn't work inside containers.

Changes:
- Added --dns option to BuildCommand to accept DNS nameserver IP
addresses
- Modified build logic to detect DNS configuration changes and recreate
the builder container when DNS settings differ
- Passed DNS configuration to BuilderStart.start() method
- Updated builder container creation to use specified DNS nameservers or
fall back to network gateway

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

## Motivation and Context
This change adds --dns parameter support to the build command, matching
the existing functionality in the run command. This allows users to
specify custom DNS nameservers (like Google DNS 8.8.8.8) when building
container images, which is essential when the host machine uses a local
DNS resolver (e.g., 127.0.0.2) that doesn't work inside containers.

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

---------

Co-authored-by: J Logan <sgtbakerrahulnet@yahoo.com>
2026-01-23 13:01:26 -08:00
J Logan 55f211251c Place image store data correctly for app-root path. (#1085)
- Closes #1084.
2026-01-23 11:35:10 -08:00
ChengHao Yang 5746ec35b3 Fix: prevent delete default network (#1083)
- Fixed #1073
- Move the conditional check to the front; there's no need
  to check for a default network after filtering.

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
2026-01-23 11:32:59 -08:00
Saehej Kang c42108d3df [image-inspect]: stdout/stderr and logging refactor (#1044)
- Relates to #642.
- Each image carries it own error message (allows for different error
types per image)
- Stdout/stderr support
- Use of the new `StderrLogHandler`
2026-01-21 22:00:03 -08:00
J Logan 2b18fc5870 Use StderrLogHandler for rich logging features. (#1066)
- Facilitates #507, #642.
- Plumb logger with logger option access into every command.
- StderrLogHandler allows logging to be enhanced for ANSI color mode for
log levels, JSONL log output, replacing `--debug` with `--level level`.
- Global logger is now just an Application.swift fileprivate only used
for initial args processing.
- Log with timestamp at debug and trace level.
- Metadata output is crude at present; we can refine this in a
follow-up.
2026-01-20 14:38:29 -08:00
Kathryn Baldauf 94d5529fc4 Use configuration subnet and fallback to default subnet in allocation only plugin (#1057)
## Type of Change
- [x] Bug fix

## Motivation and Context
This PR changes the behavior of the Allocation Only vmnet network plugin
to use the default subnet in the fallback case if no subnet was
specified in the network configuration. This matches the behavior of
`ReservedVmnetNetwork`.

## Testing
- [x] Tested locally
2026-01-19 19:23:06 -08:00
Kathryn Baldauf 9032d73d07 Change behavior of the default arguments in the plugin config (#1063)
## Type of Change
- [x] New feature  
- [x] Breaking change

## Motivation and Context
This PR changes the behavior of the `defaultArguments` field in the
service plugin config. Previously, `defaultArguments` was functioning as
a way to indicate how to start a plugin in the event that the plugin is
loaded at boot (such as for the `container-core-images plugin`).
However, we now follow a convention where all plugins have a "start"
command that is used when launching the plugin, so this
`defaultArguments` field wasn't really providing much. Instead, there
are use cases where we may want to set default values to pass to a
plugin. This PR repurposes the `defaultArguments` field for those use
cases.

As an example use case, there are scenarios where someone may want to
use the AllocationOnlyVmnetNetwork even when running on macOS 26+. This
PR adds the ability to pass in a command line option to the vmnet
network plugin to specify that request. Combined with the
`defaultArguments` plugin config change, a user may choose to set that
field to ["--variant", "allocationOnly"] in the
`container-network-vmnet-config.json` to use AllocationOnlyVmnetNetwork
by default for all networks.

## Testing
- [x] Tested locally
2026-01-19 19:22:55 -08:00
jwhur 69445b91b3 Throw error when starting a container with invalid virtiofs source (#1051)
Run = Create + Start

1) Mount source points to a valid directory
- Run and Create + Start both correctly create the container with mount.

2) Mount source points to a file
   - Run fails bootstrapping the container, thus container not created.
- Create creates the container, but Start fails bootstrapping, removing
the container. (Thus, both are the same.)

3) Mount source deleted or replaced to file after container created
   - Start throw errors but do not delete the container.
2026-01-19 13:09:34 -08:00
Danny Canter 08f48d9ab9 ContainerSvc: Handle unexpected sandbox svc exits (#1065)
Closes https://github.com/apple/container/issues/1050

If the sandbox svc exits out of band of the usual stop (or regular exit)
case the container svc's state is not properly updated for the
container. This was due to the cleanup steps involving trying to send
the shutdown rpc which cannot succeed as the sandbox svc does not exist
to service it.

To handle this, let's treat shutdown not returning successfully as
non-fatal (as this is mostly best effort), log an error and continue the
state cleanup.
2026-01-16 21:48:58 -08:00
Amir Alperin b928e3ff1d fix: performance warning should not output ANSI codes if stderr redirected (#1059) 2026-01-16 21:43:48 -08:00