# Where Is the Main Entry Point for the Apple/Container Project?

> Discover the main entry point for the apple/container project. Locate the executable 'container' in Sources/CLI/ContainerCLI.swift, defined in Package.swift.

- Repository: [Apple/container](https://github.com/apple/container)
- Tags: internals
- Published: 2026-07-06

---

**The main entry point for the apple/container project is the `ContainerCLI` struct marked with the `@main` attribute in [`Sources/CLI/ContainerCLI.swift`](https://github.com/apple/container/blob/main/Sources/CLI/ContainerCLI.swift), which compiles into an executable named `container` defined in [`Package.swift`](https://github.com/apple/container/blob/main/Package.swift).**

The apple/container repository provides a Swift-based toolchain for container operations. Understanding its main entry point is essential for contributors debugging startup behavior or extending CLI functionality. The project leverages Swift’s concurrency features and the ArgumentParser library to bootstrap execution through a specifically annotated structure.

## The ContainerCLI Entry Point in Sources/CLI/ContainerCLI.swift

The executable logic originates in [`Sources/CLI/ContainerCLI.swift`](https://github.com/apple/container/blob/main/Sources/CLI/ContainerCLI.swift), where the `ContainerCLI` type is defined. According to the apple/container source code, lines 21–32 contain the struct declaration that implements `AsyncParsableCommand` from the Swift ArgumentParser library.

```swift
import ArgumentParser

@main
struct ContainerCLI: AsyncParsableCommand {
    static func main() async throws {
        // Forward to Application helper for sub-command routing
        try await Application.main()
    }
}

```

### @main Attribute and AsyncParsableCommand

The `@main` attribute tells the Swift compiler that this struct supplies the program’s entry point. By conforming to `AsyncParsableCommand`, `ContainerCLI` inherits asynchronous command-parsing capabilities. This combination allows the `container` binary to handle async operations naturally while parsing command-line arguments through the standard ArgumentParser interface.

## Package.swift Executable Target Configuration

The package manifest ([`Package.swift`](https://github.com/apple/container/blob/main/Package.swift)) registers the source file as an executable target. Lines 74–81 declare a target named `container` that points to the `Sources/CLI` directory:

```swift
// From Package.swift (lines 74-81)
.executableTarget(
    name: "container",
    dependencies: [
        .product(name: "ArgumentParser", package: "swift-argument-parser"),
        // ... other dependencies
    ],
    path: "Sources/CLI"
),

```

When the package is built, the compiler produces a binary called `container` that starts execution at the `ContainerCLI` struct. This binding connects the Swift Package Manager build system to the `@main` annotated entry point.

## How the Entry Point Boots the Application

The `main()` static method in `ContainerCLI` does not handle command parsing directly. Instead, it forwards execution to the `Application` helper, which parses the command-line arguments and runs the appropriate sub-commands. This architecture separates the entry point declaration from the actual command routing logic, keeping the [`ContainerCLI.swift`](https://github.com/apple/container/blob/main/ContainerCLI.swift) file focused solely on bootstrapping.

The `Application` type (located elsewhere in `Sources/CLI/`) coordinates between the various service modules—such as `ContainerAPIClient` and `ContainerCommands`—that perform the actual container operations after arguments are parsed.

## Building and Running the Container Binary

To compile and run the entry point from a local checkout:

```bash

# Build the executable in release mode

swift build -c release

# Run the CLI (the binary is placed under .build/release/)

.build/release/container --help

```

The resulting binary executes the `ContainerCLI.main()` method, which initializes the application context and dispatches to the appropriate sub-command based on the arguments provided.

## Summary

- **ContainerCLI** in [`Sources/CLI/ContainerCLI.swift`](https://github.com/apple/container/blob/main/Sources/CLI/ContainerCLI.swift) serves as the main entry point for the apple/container project.
- The **@main** attribute marks this struct for the Swift compiler, with the entry logic defined at lines 21–32.
- **Package.swift** lines 74–81 define the `container` executable target that binds the source directory to the compiled binary.
- The `main()` method delegates to the **Application** helper for sub-command routing and argument parsing.

## Frequently Asked Questions

### What file contains the main entry point for apple/container?

The main entry point is defined in [`Sources/CLI/ContainerCLI.swift`](https://github.com/apple/container/blob/main/Sources/CLI/ContainerCLI.swift). This file contains the `@main` annotated `ContainerCLI` struct that the Swift compiler uses as the program’s starting point.

### How does Swift know where to start execution in the container project?

The Swift compiler recognizes the `@main` attribute attached to the `ContainerCLI` struct. This attribute designates the struct’s `main()` method as the program’s entry point, eliminating the need for a traditional [`main.swift`](https://github.com/apple/container/blob/main/main.swift) file.

### What is the name of the executable produced by the apple/container package?

The executable is named `container`. This is defined in [`Package.swift`](https://github.com/apple/container/blob/main/Package.swift) where the executable target is declared with `name: "container"`, and the build process produces a binary with that name in the `.build/release/` directory.

### Does ContainerCLI handle command parsing directly?

No, `ContainerCLI` delegates command parsing and sub-command routing to the `Application` helper. The `ContainerCLI.main()` method acts as a thin wrapper that forwards execution to the application bootstrap logic after the entry point is hit.