apple / apple/container

[Bug]: port (-p flag) connection reset by peer

Open
#1,180 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
49.9k
Forks
1.8k
Avg merge
1d 20h
Merged PRs (30d)
22

Description

### I have done the following

- [x] I have searched the existing issues
- [x] If possible, I've reproduced the issue using the 'main' branch of this project

### Steps to reproduce

Create a Dockerfile:

```
FROM node:alpine

WORKDIR /app

RUN echo 'const http = require("http"); \
const server = http.createServer((req, res) => { \
res.writeHead(200, {"Content-Type": "text/plain"}); \
res.end("Hello world"); \
}); \
server.listen(5866, () => { \
console.log("Server listening on port 5866"); \
});' > server.js

CMD ["node", "server.js"]
```

Build:

```
container build -t port-test .
```

Run:

```
container run --rm --name port-test -p 5866:5866 port-test
```

❌ Test issue:

```
❯ curl http://localhost:5866
curl: (56) Recv failure: Connection reset by peer
❯ curl http://127.0.01:5866
curl: (56) Recv failure: Connection reset by peer
```

Note that using port works out, e.g.

```
❯ container inspect port-test | jq '.[0].networks[0].ipv4Address'
"192.168.64.10/24"
❯ curl http://192.168.64.10:5866
Hello world%
```

### Current behavior

Binding port with `-p` flag when running the container appears to be configured but connections are immediately reset when accessed through `localhost` or `127.0.0.1`.

Direct container IP access works fine though.

### Expected behavior

As with Docker or Podman, being able to access a bound port through `localhost` or `127.0.0.1`.

### Environment

```markdown
- OS: macOS 26.2
- Xcode: 26.2
```

### Relevant log output

```shell
N/A
```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the supplied Dockerfile, `container build`, `container run -p 5866:5866`, and localhost curl commands, then compare them with direct container-IP access. Trace the port-forwarding path responsible for localhost connections; done means the Node server is reachable through both localhost and 127.0.0.1 without connection resets.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, macos, node.js
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.