Skip to content

mocker compose does not forward published ports to host (ECONNREFUSED) #19

@itxtoledo

Description

@itxtoledo

Description

mocker compose up does not forward published ports to the host. The containers start, mocker compose ps shows the port mappings, and mocker inspect lists them — but the ports are never actually reachable from the host (always ECONNREFUSED).

Meanwhile, using the native container run -p directly does forward ports correctly. This suggests mocker compose is not translating the ports: section from compose.yaml into the equivalent container run -p invocation.

Steps to Reproduce

1. Minimal compose.yaml

services:
  web:
    image: nginx:alpine
    ports:
      - "18080:80"

2. Start with mocker compose

$ mocker compose up -d
[+] Running 1/1
 ✔ Container mocker-issue-repro-web-1  Started

3. Verify port is shown as mapped

$ mocker compose ps
NAME                       IMAGE          SERVICE   STATUS  PORTS
mocker-issue-repro-web-1   nginx:alpine   web       Up      18080:80/tcp

$ mocker inspect mocker-issue-repro-web-1 | jq '.[0].ports'
[
  {
    "containerPort": 80,
    "hostPort": 18080,
    "portProtocol": "tcp"
  }
]

4. Try to reach the port — fails

$ node -e "require('net').createConnection(18080, '127.0.0.1', () => console.log('OK')).on('error', e => console.log(e.code))"
ECONNREFUSED

Every port published via mocker compose returns ECONNREFUSED. Tested with: mariadb, redis, maildev, s3mock, adminer, nginx — all same result.

5. Same image with native container run -p — works

$ container run -d --name repro-native -p 18081:80 nginx:alpine

$ node -e "require('net').createConnection(18081, '127.0.0.1', () => console.log('OK')).on('error', e => console.log(e.code))"
OK

6. Inspect reveals the gap

container inspect on a native container does not show ports in its configuration, while mocker inspect does show them — meaning mocker records the port mapping in its own metadata but never passes it to the underlying container runtime.

$ container inspect repro-native | jq '.[0].configuration.ports'
null

Expected Behavior

mocker compose up should forward published ports to the host, just like container run -p does natively.

Environment

  • mocker: 0.2.0 (client and server)
  • container: 1.0.0 (commit ee848e3)
  • container-apiserver: 1.0.0 (commit ee848e3)
  • macOS: 26.2 (25C56)
  • Architecture: arm64 (Apple Silicon)

Workaround

Use container run -p directly instead of mocker compose:

container run -d --name myapp -p 8080:80 nginx:alpine

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions