[Bug]: --publish rejects port 1 as out of range

Open Beginner friendly
#2,014 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
swift
Domain
cli

Research direction

Start in Sources/Services/ContainerAPIService/Client/Parser.swift at Parser.publishPort around line 704, then run the two --publish reproductions from the issue. Done means port 1 is accepted for host, container, and range endpoints while port 0 remains rejected.

Written by the indexing model from the issue text.

Description

I have done the following
  • I have searched the existing issues
  • If possible, I've reproduced the issue using the 'main' branch of this project
Steps to reproduce

Publish either side of a port mapping on port 1:

container run --rm --publish 1:80 nginx
container run --rm --publish 8080:1 nginx

Both fail:

invalid publish host port range: 1
invalid publish container port range: 1
Problem description

Parser.publishPort validates the parsed range with a strict greater-than:

https://github.com/apple/container/blob/main/Sources/Services/ContainerAPIService/Client/Parser.swift#L704

guard hostPortRangeStart > 1,
    hostPortRangeStart <= hostPortRangeEnd
else { ... }

guard containerPortRangeStart > 1,
    containerPortRangeStart <= containerPortRangeEnd
else { ... }

TCP and UDP port numbers run from 1 to 65535, so the lower bound should be >= 1. The current comparison also rejects port 1 at the start of a range, so --publish 1-100:1-100 fails as well.

Port 0 is correctly rejected either way, since it means "any port" rather than a specific one.

Environment
  • OS: macOS 26.5.2 (25F84)
  • Xcode: 26.6 (17F113)
  • Container: main at 07ff3c0 (also present in 1.1.0)
Code of Conduct
  • I agree to follow this project's Code of Conduct
Dominant language
Swift
Stars
50.1k
Forks
1.8k
Avg merge
2d 2h
Merged PRs (30d)
19

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apple/container

All issues in apple/container

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.