48 Commits

Author SHA1 Message Date
J Logan 3b5c253059 Adds container network for macOS 26. (#243)
See discussion below for example. For multiple network interfaces in a
single container we'll want to integrate against a containerization that
includes apple/containerization#156.

The change bumps the containerization dependency to 0.2.0 and addresses
the breaking API changes.

```console
% container network
OVERVIEW: Manage container networks

USAGE: container network <subcommand>

OPTIONS:
  --version               Show the version.
  -h, --help              Show help information.

SUBCOMMANDS:
  create                  Create a new network
  delete, rm              Delete one or more networks
  list, ls                List networks
  inspect                 Display information about one or more networks

  See 'container help network <subcommand>' for detailed help.
```
2025-06-27 14:12:29 -07:00
Eliseo Martelli b5589f7f8c Improve error handling in answerHost (#226)
Refactor `answerHost` to throw descriptive `DNSResolverError` instances
instead of returning nil when IP allocation or parsing fails.
2025-06-27 10:29:25 -07:00
Dmitry Kovba de2be705de Remove the support for CURRENT_SDK (#251)
This PR removes the no longer needed support for `CURRENT_SDK`.
2025-06-26 10:40:34 -04:00
Sidhartha Mani c7c88c2e34 [Build] Do not use unbounded DispatchIO readers for tar tranfers (#257)
- Addresses https://github.com/apple/container/issues/166
- Memory utilization explodes since there is no mechanism for
backpressure
- Using a synchronous buffered reader seem to provide similar
performance without the memory explosion issue
- 4MB buffer seems to provide the best results

| Metric | 1MB Buffer | 4MB Buffer | Unbounded Zero-Copy |

|--------------------------|------------|------------|---------------------|
| Build Time | 149.33s | 138.57s | 139.79s |
| Max RAM Used | 2.16 GB | 3.02 GB | 3.52 GB |
| Peak Memory Footprint | 8.30 GB | 8.17 GB | 10.21 GB |
| Page Reclaims | 1,085,559 | 1,039,677 | 1,619,943 |
| Page Faults | 115 | 148 | 143 |
| CPU Usage (User+Sys) | 53.71s | 53.12s | 60.44s |
2025-06-25 13:51:51 -07:00
Kathryn Baldauf 4a6a1f15d8 Add test that we replace meta args in builder correctly (#255)
Depends on https://github.com/apple/container-builder-shim/pull/24 

Related to https://github.com/apple/container/issues/252

---------

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-24 13:25:58 -07:00
Renee Chang a69ed78484 Add socket publishing functionality (#236)
Signed-off-by: renee chang <rchang25@apple.com>
2025-06-20 09:00:47 -07:00
Spencer Heywood a262d8fc6a provide suggestion if xpc 'Connection invalid' error encountered (#179)
Closes https://github.com/apple/container/issues/80

Adds the following help message if you try to run `container` against a
host that hasn't started the container system:

```
❯ /usr/local/bin/container list
Error: internalError: "failed to list containers" (cause: "interrupted: "Connection invalid: ensure container system has been started with `container system start`"")

❯ /usr/local/bin/container run -it --rm docker.io/alpine
Error: interrupted: "Connection invalid: ensure container system has been started with `container system start`"
```
2025-06-19 00:12:57 -07:00
Ramsyana 21cfebb475 Fix Race Condition in Container Removal (#130) (#218)
This PR resolves a race condition when removing a container immediately
after stopping it, caused by the `stop` command returning before the
container fully transitions to the stopped state (#130).

**Changes:**
- Enhanced `TestCLIRmRace.swift` with robust test logic and helper
methods (`containerExists`, `safeRemove`).
- Improved error handling to distinguish race conditions from successful
removals.
- Added exponential backoff retry logic for cleanup operations.
- Updated `CLITest.swift` with missing `doRemove` method.
- Fixed `BuilderStart.swift` to handle `.stopping` case.
- Improved error messages with container ID for better debugging.

**Testing:**
-  All tests pass (`make test`, `make integration`).
-  Verified on macOS 26.
-  Race condition test validates success and failure scenarios.
-  Code formatted (`make fmt`).

Hopefully, this will pass the integration tests on GitHub.

Signed-off-by: ramsyana <47033578+ramsyana@users.noreply.github.com>
2025-06-16 23:19:46 -07:00
Dmitry Kovba 0535d36929 Fix warnings in make docs (#220) 2025-06-16 17:55:48 -07:00
Aditya Ramani 4c171d4641 Wait for IO streams to complete before a process exits (#198)
Implements a way for the CLI to wait until the IO streams from the
SandboxService have been drained before closing them.

Follows the same pattern as
https://github.com/apple/containerization/pull/110

This change also performs some cleanup in the
`SandboxService.startProcess` method - splitting the code paths to
handle the init process and an exec'd process into two different private
methods to make easier reading

---------

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-16 13:41:56 -07:00
Michael Crosby 011e6764f7 use rotatingAllocator for ipam (#217)
Signed-off-by: crosbymichael <michael_crosby@apple.com>
2025-06-16 11:03:57 -07:00
Josh Soref 4a4ad40d74 Spelling (#207)
This PR corrects misspellings identified by the [check-spelling
action](https://github.com/marketplace/actions/check-spelling)

The misspellings have been reported at
https://github.com/jsoref/container/actions/runs/15662939575/attempts/1
The action reports that the changes in this PR would make it happy:
https://github.com/jsoref/container/actions/runs/15662939742/attempts/1#summary-44123289718

---------

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2025-06-16 10:49:03 -07:00
Danny Canter 4d6f7037f3 Plugins: Remove unused devnull var (#214)
We actually use the output (both stderr and stdout) of the command.
2025-06-16 08:11:25 -07:00
Dmitry Kovba 555dbfc9fa Adds a warning when running a debug build (#201)
This PR adds a warning that the performance may be degraded when running
a debug build.

Debug build:
```
% bin/container run -it --rm alpine:latest date
Warning! Running debug build. Performance may be degraded.
Fri Jun 13 18:10:35 PDT 2025
```

Release build:
```
% bin/container run -it --rm alpine:latest date
Fri Jun 13 18:10:35 PDT 2025
```
2025-06-13 19:48:59 -07:00
Eliseo Martelli 84798601cd Throw errors in ServiceManager (#188) 2025-06-13 17:07:55 -07:00
Noritaka Kobayashi 098021fc5b refactor: fix typos (#77)
fix typos
2025-06-13 16:42:07 -07:00
Aditya Ramani c5392e838f Remove the system restart command (#196)
Closes https://github.com/apple/container/issues/175

Also does some housekeeping - update availability checks and fix a typo

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-13 13:45:25 -07:00
Patrick Stöckle 84edaa20db Fix typos (#122)
Hi there,

some small typos I fixed using
[`typos`](https://github.com/crate-ci/typos).

Cheers,
Patrick
2025-06-13 11:07:07 -07:00
Alexey Makhov 2a12f01d32 container registry login host:port error fix (#170)
Fixes #121

Gets port from the given registry server URL and use it in a
RegistryClient.

Signed-off-by: Alexey Makhov <makhov.alex@gmail.com>
2025-06-13 07:33:05 -07:00
Dmitry Kovba 206f3cc07c Improve accuracy of progress updates (#144)
This PR resolves the problem of dropped progress updates and ensures the
accuracy of the information provided in the progress bar. Additionally,
it adds the displaying of the finished state to the progress bar.
Requires merging and tagging
https://github.com/apple/containerization/pull/91.
2025-06-12 23:36:38 -07:00
Yibo Zhuang 8f2d4d7300 Fix: consolidate UserDefaults service name (#161)
This change consolidates the UserDefaults service name
`com.apple.container.defaults` to a single constant under the extension
file and also renamed the extension file.

Signed-off-by: Yibo Zhuang <yibzhuang@gmail.com>
2025-06-12 21:28:24 -07:00
Ümit DEMİRCİ c114945f15 fix: typo (#153) 2025-06-12 17:14:15 -07:00
Elijah Wright 7ca5a4313f define JSONDecoder() outside of for loop in load() (#159)
this PR defines a variable, `decoder`, which represents the
`JSONDecoder` class, rather than doing it in the for loop in `load()`

Signed-off-by: Elijah Wright <git@elijahs.space>
2025-06-12 11:37:26 -07:00
Kathryn Baldauf 3838be5207 Update protos and add builder shim version in Package.swift (#176)
This PR updates the protos to match the recent changes in
https://github.com/apple/container-builder-shim/pull/15.

This PR additionally adds the builder shim version as a variable in
Package.swift. This allows us to be consistent with the builder tag used
for the builder shim image and when building protobuf files.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-12 10:51:00 -07:00
Kathryn Baldauf 37fc68fee0 Add the option to disable progress updates on image CLI calls (#146)
Closes https://github.com/apple/container/issues/126 

This PR additionally removes the ability to set
`disable-progress-updates` for `container create` calls while we
investigate why output get jumbled there.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-11 13:12:10 -07:00
Daniel Gonzalez 20b63255ac Add new system status command (#118)
Container services can be started and stopped using the `system start`
and `system stop` commands. But there is no straightforward way for
users to check if the services were already started.

This PR adds a new `system status` command that shows wether the
container services are running or not.

The command only checks the status of the apiserver for now, but it
could be expanded in the future to show more details.

Fixes #117.
2025-06-10 16:30:59 -07:00
Kathryn Baldauf 3a76848e18 Remove unused flags from registry login (#128)
fixes https://github.com/apple/container/issues/120 

These flags were unused, so remove for clarity.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-10 16:08:22 -07:00
Aditya Ramani 7efc0f371b Skip unpacking unsupported platforms (#127)
This is a more appropriate fix for
https://github.com/apple/container/issues/61 - which was closed by use
of a workaround.
There is no need to unpack image variants that we dont support.

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-10 16:07:01 -07:00
SADIK KUZU a7c974e968 Fix typo in Parser.swift (#64) 2025-06-09 15:53:49 -07:00
Aditya Ramani 523cfe4f52 Bump to using Containerization 0.1.0 (#50)
Also update the `container-builder-shim` image to 0.1.0

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-09 11:18:49 -07:00
Eric Ernst 9e3d32e08c update code comments for consistent macOS descriptions (#51) 2025-06-09 11:12:03 -07:00
J Logan 5a43b0abac Use python:alpine for tutorial. (#46) 2025-06-09 07:52:52 -07:00
Sidhartha Mani 7020082723 [Build] purely-lexical URL operations for resolving symlinks (#31)
`BuildFSSync.walk` relied on an implementation detail to skip traversing
the path ".", relative to the build context dir.

Specifically, it assumed that:
- `URL.parentOf()` would return false when the parent argument was
relative.
- `URL.path(percentEncoded: false)` would preserve the relativity of an
input path.
These assumptions held on earlier macOS releases, so the context
directory silently remained untouched.

In some versions of macOS , `URL.path(percentEncoded: false)` always
returns an absolute path, regardless of how the URL was created. Because
of this change, `URL.parentOf()` now returns true for ".", and
BuildFSSync.walk begins descending into the context directory—something
it was never meant to do.

This solution:
- Remove the hidden dependency on `URL.parentOf()` for context‑directory
detection.
- Add an explicit check for "." inside BuildFSSync.walk and bail out
early.

Replace fragile calls to `URL.path(percentEncoded: false`) with the
stable, documented `URL.relativePath`, which preserves relativity when
the original path was relative.
2025-06-07 15:32:06 -07:00
Aditya Ramani f86dcefb04 Add make target to fetch the default kernel (#33)
Replaces the `--install-dependencies` flag with the
`(enable/disable)-kernel-install` flag. If the flag is not passed - the
default behavior is prompting the user for a response.

Also adds a make target `install-kernel`

```
➜ bin/container system start
Verifying apiserver is running...
Installing base container filesystem...
No default kernel configured.
Install the recommended default kernel from [https://github.com/kata-containers/kata-containers/releases/download/3.17.0/kata-static-3.17.0-arm64.tar.xz]? [Y/n]: n
Please use the `container system kernel set --recommended` command to configure the default kernel

➜ bin/container system start --disable-kernel-install
Verifying apiserver is running...

➜ bin/container system start --enable-kernel-install
Verifying apiserver is running...
Installing kernel...

➜ bin/container system start --help

USAGE: container system start ... [--enable-kernel-install] [--disable-kernel-install]
...
  --enable-kernel-install/--disable-kernel-install
                          Specify if the default kernel should be installed or not.

```

---------

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-07 12:45:45 -07:00
J Logan 6fe813a9da Bulk up docc for ContainerSandboxService. (#32) 2025-06-06 16:36:49 -07:00
Kathryn Baldauf 7523d68251 Update to containerization 0.0.3 (#21)
Update containerization to take new breaking changes
https://github.com/apple/containerization/pull/22

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-06 14:39:51 -07:00
Aditya Ramani 5d80ca8d40 Extend NSLock to accept a closure (#28)
Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-06 12:08:47 -07:00
Dmitry Kovba 8ad99efdbc Allow printed output to flush to prevent a race between progress updates and other output (#23)
This PR also improves clearing the last progress update after moving to
a new task using `setDescription()`.
2025-06-06 11:48:22 -07:00
Arnav Reddy cd94337f27 Truncate container log files to remove logging delay on restarted container (#26)
When a container that was writing stdout/stderr to its dedicated
container log file was stopped and started, there was a ~20 second - 1
minute delay from when the init process was restarted and when the
output of the process was written to the log file. This also meant there
was a delay when streaming those logs using `container logs -f`. The
logs from that delay period were lost.

This change forces the container log file to update state after a
container restart which fixes the delays to the container log file. And
the` container logs -f` stream resets its position in the file on a
container restart as well.

---------

Co-authored-by: Arnav Reddy <areddy23@apple.com>
2025-06-06 11:27:34 -07:00
Aditya Ramani 007f9a41f7 Update kernel install UX (#22)
This change updates the UX when we install required dependencies at
first launch


### Fresh install - respond `y` to prompt
```
➜ bin/container system start
Verifying apiserver is running...
Installing base container filesystem...
No default kernel configured.
Install the recommended default kernel from [https://github.com/kata-containers/kata-containers/releases/download/3.17.0/kata-static-3.17.0-arm64.tar.xz]? [Y/n]: y
Installing kernel...
```


### Fresh install - respond `n` to prompt and then run the provided
command
```
➜ bin/container system start
Verifying apiserver is running...
Installing base container filesystem...
No default kernel configured.
Install the recommended default kernel from [https://github.com/kata-containers/kata-containers/releases/download/3.17.0/kata-static-3.17.0-arm64.tar.xz]? [Y/n]: n
Please use the `container system kernel set --recommended` command to configure the default kernel

➜ bin/container system kernel set --recommended
Installing the recommended kernel from https://github.com/kata-containers/kata-containers/releases/download/3.17.0/kata-static-3.17.0-arm64.tar.xz...
```


### Fresh install - respond `n` to prompt and then run a container
```
➜ bin/container system start
Verifying apiserver is running...
Installing base container filesystem...
No default kernel configured.
Install the recommended default kernel from [https://github.com/kata-containers/kata-containers/releases/download/3.17.0/kata-static-3.17.0-arm64.tar.xz]? [Y/n]: n
Please use the `container system kernel set --recommended` command to configure the default kernel

➜ bin/container run alpine uname
Error: notFound: "Default kernel not configured for architecture arm64. Please use the `container system kernel set` command to configure it
```

---------

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-05 18:09:36 -07:00
Dmitry Kovba 27df947172 Clear a line with spaces to prevent a race between stderr and stdout (#18)
This PR resolves a race with `\u{001B}[2K`, but not with `\r`, which
will be addressed in a separate PR by moving progress updates to
`stdout`. Please test it in a small window in your terminal application
on the `users/a_ramani/install-ux` branch using commands:
```
bin/container system stop
make cleancontent
bin/container system start
```
You should see the prompt:
> Install the recommended default kernel from
[https://github.com/kata-containers/kata-containers/releases/download/3.17.0/kata-static-3.17.0-arm64.tar.xz]?
[Y/n]:
2025-06-05 15:53:45 -07:00
Aditya Ramani e5aceaaff1 Cleanup output from --version (#16)
The output now looks like the following

#### When build against a tagged HEAD in `RELEASE` mode
```
container --version
container CLI version 0.0.2 (build: release, commit: ed4a4cb)
```
2025-06-05 15:53:40 -07:00
Aditya Ramani 0846bb6640 Create RequestScheme type to handle registry interactions (#6)
Its a bit weird to have to pass `--http` when pulling / pushing images
if we are trying to do so from a local registry

This PR adds a `RequestScheme` enum type which tries to detect if the
connection to the registry should be over http or https. This auto
detection is the default behavior and can be overridden by passing the
`--scheme http/https` flag to the `run` ,`pull`, `push` `login` and
`registry default` command

The auto detection works by looking at the hostname / IP. HTTP is used
in the following cases
 - If the hostname starts with `localhost` or  is `127.x.x.x`
 - if the host looks like an IP from the private address space
 - If the host ends with the current default dns domain name

Also in this PR:
- Removing some used CLI flag groups and TODOs
- Better error messages when registry credentials are not found for a
host

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-05 15:53:01 -07:00
Aditya Ramani 8a6a593eee Selectively uncompress kernel binary from archive (#7) 2025-06-05 15:52:39 -07:00
Aditya Ramani f12593c3c2 Register existing runtime plugin launch units on boot (#5) 2025-06-05 15:52:35 -07:00
Kathryn Baldauf 3a6d7ae676 Cherry pick additional changes (#3)
* Format the codebase (#50)

Signed-off-by: Aditya Ramani <a_ramani@apple.com>

* Update packages before going public (#48)

---------

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
Co-authored-by: Aditya Ramani <a_ramani@apple.com>
Co-authored-by: dkovba <dkovba@apple.com>
2025-06-05 15:52:26 -07:00
Kathryn Baldauf 31a0cb2f4e Update alpine images used (#1)
Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-05 15:52:13 -07:00
Kathryn Baldauf 8e9670c8f8 Initial commit
Co-authored-by: Aditya Ramani <a_ramani@apple.com>
Co-authored-by: Agam Dua <agam_dua@apple.com>
Co-authored-by: Danny Canter <danny_canter@apple.com>
Co-authored-by: Dmitry Kovba <dkovba@apple.com>
Co-authored-by: Eric Ernst <eric_ernst@apple.com>
Co-authored-by: Evan Hazlett <ehazlett@apple.com>
Co-authored-by: Gilbert Song <gilbertsong@apple.com>
Co-authored-by: Hugh Bussell <hbussell@apple.com>
Co-authored-by: John Logan <john_logan@apple.com>
Co-authored-by: Kathryn Baldauf <k_baldauf@apple.com>
Co-authored-by: Madhu Venugopal <mvenugopal@apple.com>
Co-authored-by: Michael Crosby <michael_crosby@apple.com>
Co-authored-by: Sidhartha Mani <sidhartha_mani@apple.com>
Co-authored-by: Tanweer Noor <tnoor@apple.com>
Co-authored-by: Ximena Perez Diaz <xperez528@gmail.com>
Co-authored-by: Yibo Zhuang <yzhuang@apple.com>
2025-06-05 15:51:55 -07:00