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:
siikamiika
2025-10-13 16:30:10 -07:00
committed by GitHub
parent 89c69d6271
commit d8eb510e1e
2 changed files with 5 additions and 1 deletions
@@ -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)
}
+1
View File
@@ -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)`