Skip to content

Add --ip flag to container create and run - #41374

Merged
beena352 merged 2 commits into
microsoft:masterfrom
beena352:users/beenachauhan/container-ip-address
Aug 19, 2026
Merged

Add --ip flag to container create and run#41374
beena352 merged 2 commits into
microsoft:masterfrom
beena352:users/beenachauhan/container-ip-address

Conversation

@beena352

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Adds --ip support to wslc container create and wslc container run, allowing users to assign a static IPv4 address to a container's primary network endpoint. This mirrors the existing --network-alias plumbing, the backend was already wired; this PR adds the CLI argument, validation, and launcher integration.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

  • Registers ArgType::IpAddress in both ContainerRunCommand and ContainerCreateCommand
  • Parses it in ContainerTasks.cpp into ContainerOptions::IpAddress (std::optionalstd::string)
  • Validates in ContainerService::CreateInternal with the same three-check pattern as --network-alias: requires a user-defined network, rejects multiple networks, rejects built-in modes (bridge/host/none/container:*)
  • Passes through WSLCContainerLauncher::SetPrimaryNetworkIpAddress → KVP {"IPAddress", ...} in the primary endpoint settings batch

Validation Steps Performed

  • WSLCTests.cpp - added two blocks inside the existing NetworkAliasCreateTest omnibus: a happy-path that round-trips IP + alias together through the launcher, and a rejection block verifying the service-layer guard fires for host/none modes
  • WSLCE2EContainerRunTests.cpp - 5 new tests: success (asserts both endpoint.IPAddress and IPAMConfig->IPv4Address), no-network rejected, bridge-mode rejected, multiple-networks rejected, invalid IP rejecte
  • WSLCE2EContainerCreateTests.cpp - same 5 tests mirrored, asserting IPAMConfig->IPv4Address only (container is created, not started, so endpoint.IPAddress is not populated)

Copilot AI lite review requested due to automatic review settings August 18, 2026 18:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds --ip support to wslc container create and wslc container run, enabling callers to request a static IPv4 address for a container’s primary network endpoint and plumbing that value through the existing launcher/service wiring.

Changes:

  • Registers ArgType::IpAddress for container create / container run and maps it into ContainerOptions.
  • Adds service-layer validation for --ip (requires exactly one user-defined network) and passes the IP into WSLCContainerLauncher primary-endpoint settings.
  • Adds/extends unit + E2E coverage for success and rejection cases, plus new localized user-facing error messages.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/windows/WSLCTests.cpp Adds launcher-level tests for IP + alias round-tripping and service-layer rejection in unsupported network modes.
test/windows/wslc/e2e/WSLCE2EContainerRunTests.cpp Adds E2E coverage for container run --ip success and validation failures.
test/windows/wslc/e2e/WSLCE2EContainerCreateTests.cpp Adds E2E coverage for container create --ip success and validation failures.
src/windows/wslc/tasks/ContainerTasks.cpp Parses --ip into ContainerOptions::IpAddress.
src/windows/wslc/services/ContainerService.cpp Validates --ip vs. network selection and forwards to the launcher.
src/windows/wslc/services/ContainerModel.h Adds ContainerOptions::IpAddress (currently contains unresolved merge conflict markers).
src/windows/wslc/commands/ContainerRunCommand.cpp Registers --ip for container run.
src/windows/wslc/commands/ContainerCreateCommand.cpp Registers --ip for container create.
src/windows/common/WSLCContainerLauncher.h Adds SetPrimaryNetworkIpAddress API + member storage.
src/windows/common/WSLCContainerLauncher.cpp Adds primary-endpoint KVP "IPAddress" emission when configured.
localization/strings/en-US/Resources.resw Adds localized error messages for --ip network validation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/windows/wslc/services/ContainerModel.h Outdated
Copilot AI review requested due to automatic review settings August 18, 2026 18:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/windows/common/WSLCContainerLauncher.h:70

  • SetPrimaryNetworkIpAddress takes a std::string&&, which forces callers that already hold a string (e.g. ContainerService.cpp uses options.IpAddress, and tests often have const std::string) to allocate/copy into a temporary just to satisfy the signature. Consider changing this to accept std::string_view or const std::string& (and copy internally), or take std::string by value and move into the optional, to avoid extra copies and make the API easier to call.
    void AddAdditionalNetwork(const std::string& Name, const std::vector<std::string>& Aliases);
    void AddPrimaryNetworkAlias(const std::string& Alias);
    void SetPrimaryNetworkIpAddress(std::string&& Address);

@beena352
beena352 marked this pull request as ready for review August 18, 2026 22:15
@beena352
beena352 requested review from a team as code owners August 18, 2026 22:15
@beena352
beena352 merged commit 5422fc4 into microsoft:master Aug 19, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants