mirror of
https://github.com/apple/container.git
synced 2026-09-27 17:36:08 -04:00
Add container machine for managing persistent Linux VMs (#1662)
## Type of Change
- [ ] Bug fix
- [x] New feature
- [ ] Breaking change
- [ ] Documentation update
## Motivation and Context
`container` runs each workload in an ephemeral VM, so there's no
built-in way to keep a persistent Linux environment you can log into and
work in. `container machine` adds one.
A container machine is a lightweight, persistent, and integrated Linux
environments that feel like an extension of your Mac, created from
standard OCI images with a familiar UX. The login user matches your host
account with passwordless `sudo`, your home directory is mounted inside
the VM, and each machine keeps its filesystem and runs the image's own
init system (such as`systemd` or `openrc`).
```bash
container machine create alpine:3.22 --name my-machine
container machine run -n my-machine # interactive shell
container machine set -n my-machine cpus=4 memory=8G
```
Subcommands: `create`, `run`, `list` (`ls`), `inspect`, `set`,
`set-default`, `logs`, `stop`, `delete` (`rm`); `m` aliases `machine`.
Docs added to `docs/command-reference.md` (Machine Management) and
`docs/how-to.md` ("Use container machines").
## Testing
- [x] Tested locally
- [x] Added/updated tests
- [x] Added/updated docs
Signed-off-by: Raj Aryan Singh <rajaryan_singh@apple.com>
Co-authored-by: Jaewon Hur <jaewon_hur@apple.com>
Co-authored-by: John Logan <john_logan@apple.com>
Co-authored-by: Michael Crosby <michael_crosby@apple.com>
Co-authored-by: Eric Ernst <eric_ernst@apple.com>
Co-authored-by: Danny Canter <danny_canter@apple.com>
This commit is contained in:
co-authored by
Jaewon Hur
John Logan
Michael Crosby
Eric Ernst
Danny Canter
parent
1b5576312f
commit
b2994ac369
@@ -59,7 +59,8 @@ extension Application {
|
||||
|
||||
let containers: [String]
|
||||
if all {
|
||||
containers = try await client.list().compactMap { c in
|
||||
let filters = ContainerListFilters().withoutMachines()
|
||||
containers = try await client.list(filters: filters).compactMap { c in
|
||||
// Skip running containers when using --all without --force
|
||||
if c.status == .running && !force {
|
||||
return nil
|
||||
|
||||
@@ -56,7 +56,8 @@ extension Application {
|
||||
|
||||
let containers: [String]
|
||||
if self.all {
|
||||
containers = try await client.list(filters: ContainerListFilters(status: .running)).map { $0.id }
|
||||
let filters = ContainerListFilters(status: .running).withoutMachines()
|
||||
containers = try await client.list(filters: filters).map { $0.id }
|
||||
} else {
|
||||
containers = containerIds
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ extension Application {
|
||||
|
||||
public func run() async throws {
|
||||
let client = ContainerClient()
|
||||
let filters = self.all ? ContainerListFilters.all : ContainerListFilters(status: .running)
|
||||
|
||||
let filters = ContainerListFilters(status: self.all ? nil : .running).withoutMachines()
|
||||
let containers = try await client.list(filters: filters)
|
||||
let items = containers.map { ManagedContainer($0) }
|
||||
try Output.render(payload: items, display: items, format: format, quiet: quiet)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import ArgumentParser
|
||||
import ContainerAPIClient
|
||||
import ContainerResource
|
||||
import ContainerizationError
|
||||
import Foundation
|
||||
|
||||
@@ -33,7 +34,8 @@ extension Application {
|
||||
|
||||
public func run() async throws {
|
||||
let client = ContainerClient()
|
||||
let containersToPrune = try await client.list().filter { $0.status == .stopped }
|
||||
let filters = ContainerListFilters(status: .stopped).withoutMachines()
|
||||
let containersToPrune = try await client.list(filters: filters)
|
||||
|
||||
var prunedContainerIds = [String]()
|
||||
var totalSize: UInt64 = 0
|
||||
|
||||
@@ -60,7 +60,8 @@ extension Application {
|
||||
|
||||
let containers: [String]
|
||||
if self.all {
|
||||
containers = try await client.list().map { $0.id }
|
||||
let filters = ContainerListFilters().withoutMachines()
|
||||
containers = try await client.list(filters: filters).map { $0.id }
|
||||
} else {
|
||||
containers = containerIds
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user