From d8eb510e1eb206bdbc390f5160028e4befb732f3 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Tue, 14 Oct 2025 02:30:10 +0300 Subject: [PATCH] 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: screenshot 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 --- Sources/ContainerCommands/Network/NetworkCreate.swift | 5 ++++- docs/command-reference.md | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/ContainerCommands/Network/NetworkCreate.swift b/Sources/ContainerCommands/Network/NetworkCreate.swift index b8e2719d..6b25e771 100644 --- a/Sources/ContainerCommands/Network/NetworkCreate.swift +++ b/Sources/ContainerCommands/Network/NetworkCreate.swift @@ -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) } diff --git a/docs/command-reference.md b/docs/command-reference.md index 0631c215..44cf3e39 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -527,6 +527,7 @@ container network create NAME [OPTIONS] **Options** * `--label `: set metadata labels on the network +* `--subnet `: set subnet on the network * **Global**: `--version`, `-h`/`--help` ### `container network delete (rm)`