mirror of
https://github.com/apple/container.git
synced 2026-08-28 11:26:32 +00:00
Support --subnet in network create (#737)
> [!CAUTION] > Just noticed you can actually create a network that conflicts with an existing network not managed by `network create`. Unless that is fine do not merge! Currently containerization only supports IPv4. Example: <img width="2012" height="578" alt="screenshot" src="https://github.com/user-attachments/assets/38fef1ef-3ffd-4d77-b9e2-8c43f7e4851d" /> Docker ref: https://docs.docker.com/reference/cli/docker/network/create/ Podman ref: https://docs.podman.io/en/v5.0.3/markdown/podman-network-create.1.html#subnet-subnet Fixes apple/container#458 ## Type of Change - [ ] Bug fix - [x] New feature - [ ] Breaking change - [ ] Documentation update ## Motivation and Context [Why is this change needed?] Scripted creation of deterministic network environments for containers ## Testing - [x] Tested locally - [ ] Added/updated tests - [x] Added/updated docs
This commit is contained in:
@@ -30,6 +30,9 @@ extension Application {
|
||||
@Option(name: .customLong("label"), help: "Set metadata for a network")
|
||||
var labels: [String] = []
|
||||
|
||||
@Option(name: .customLong("subnet"), help: "Set subnet for a network")
|
||||
var subnet: String? = nil
|
||||
|
||||
@OptionGroup
|
||||
var global: Flags.Global
|
||||
|
||||
@@ -40,7 +43,7 @@ extension Application {
|
||||
|
||||
public func run() async throws {
|
||||
let parsedLabels = Utility.parseKeyValuePairs(labels)
|
||||
let config = try NetworkConfiguration(id: self.name, mode: .nat, labels: parsedLabels)
|
||||
let config = try NetworkConfiguration(id: self.name, mode: .nat, subnet: subnet, labels: parsedLabels)
|
||||
let state = try await ClientNetwork.create(configuration: config)
|
||||
print(state.id)
|
||||
}
|
||||
|
||||
@@ -527,6 +527,7 @@ container network create NAME [OPTIONS]
|
||||
**Options**
|
||||
|
||||
* `--label <key=value>`: set metadata labels on the network
|
||||
* `--subnet <value>`: set subnet on the network
|
||||
* **Global**: `--version`, `-h`/`--help`
|
||||
|
||||
### `container network delete (rm)`
|
||||
|
||||
Reference in New Issue
Block a user