Skip to content

Pass container port instead of host port to Docker#12595

Merged
enyst merged 2 commits intoOpenHands:mainfrom
cbagwell:docker-work-port-fix
Feb 28, 2026
Merged

Pass container port instead of host port to Docker#12595
enyst merged 2 commits intoOpenHands:mainfrom
cbagwell:docker-work-port-fix

Conversation

@cbagwell
Copy link
Copy Markdown
Contributor

Summary of PR

WORKER_1/WORKER_2 should be port for apps to listen on so that they can be accessed externally but currently the Docker runtime sets this to the unreachable dynamic ports meant for host side usage.

This also fixes work_host skill in Docker so that it lists the correct port to listen on so that LLM chooses correct port when starting servers.

The user has access to the following hosts for accessing
a web application, each of which has a corresponding port:

* http://hostname:X (8011)
* http://hostname:Y (8012)

Demo Screenshots/Videos

n/a

Change Type

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Other (dependency update, docs, typo fixes, etc.)

Checklist

  • I have read and reviewed the code and I understand what the code is doing.
  • I have tested the code to the best of my ability and ensured it works as expected.

Fixes

Ask OpenHands to create Hello, World flask app with CORS support and run it. It will use WORKER_1 port (dynamic host port) because of work_host skill but app will not be accessible externally and the App tab will not auto-display the app. This fix will cause it to use port 8011 with Docker runtime which will make the app accessible and be visible in App tab.

Resolves #(issue)

n/a

Release Notes

  • Include this change in the Release Notes.

@cbagwell
Copy link
Copy Markdown
Contributor Author

cbagwell commented Jan 25, 2026

Tested with the following prompt and confirmed the agent used port 8011, the App tab displayed the app using the correct externally visible URL (why CORS is mentioned), and also accessible from my browser. The work_host skill prompt could debatably be improved if it included the need for CORS to work correctly with the App tab.

"Build a Flask app that displays a pretty 'Hello, World!' webpage, ensuring it runs on an externally visible port and has CORS enabled."

image

@jpelletier1
Copy link
Copy Markdown
Contributor

Thank you @cbagwell! Going to link this to #12049 for record keeping. Will see if we can find a maintainer to review.

@jpelletier1 jpelletier1 linked an issue Jan 27, 2026 that may be closed by this pull request
@cbagwell cbagwell force-pushed the docker-work-port-fix branch from 1c831aa to 87494c0 Compare January 29, 2026 01:46
@cbagwell
Copy link
Copy Markdown
Contributor Author

I'v rebased to main to resolve a merge conflict with new host networking mode. The host networking was mismatched and using host_port for one area and container_port for another area. Both are same value so either was OK but I aligned with bridge networking for consistency.

@cbagwell
Copy link
Copy Markdown
Contributor Author

cbagwell commented Jan 29, 2026

I've confirmed the rebase works correctly for new host networking mode in addition to default bridge networking. WORKER_1/2 still are fixed at 8011/8012 (same as bridge mode) and this is what work_host skill looks like for host networking mode:

The user has access to the following hosts for accessing a web application, each of which has a corresponding port:
* http://hostname:8011 (port 8011)
* http://hostname:8012 (port 8012)

I don't think the CI failure can be related to my changes but if there is something I can do to address then please let me know.

WORKER_1/WORKER_2 should be port for apps to listen on so
that they can be accessed externally but currently the
Docker runtime sets this to the unreachable dynamic ports
meant for host side usage.

This also fixes work_host skill in Docker so that it lists
the correct port to listen on so that LLM chooses correct port
when starting servers.

    The user has access to the following hosts for accessing
    a web application, each of which has a corresponding port:

    * http://hostname:X (8011)
    * http://hostname:Y (8012)
@cbagwell cbagwell force-pushed the docker-work-port-fix branch from 87494c0 to 295efa5 Compare February 19, 2026 01:42
@cbagwell
Copy link
Copy Markdown
Contributor Author

I re-reviewed and discovered I had mistakenly included uv.lock in commit which was breaking github tests. I also rebased to latest main while fixing that.

Copy link
Copy Markdown
Collaborator

@enyst enyst left a comment

Choose a reason for hiding this comment

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

Thank you!

@enyst enyst merged commit f9d553d into OpenHands:main Feb 28, 2026
14 checks passed
Cognifyi pushed a commit to Cognifyi/OpenHands that referenced this pull request Mar 1, 2026
Co-authored-by: Engel Nyst <engel.nyst@gmail.com>
@saurya saurya linked an issue Mar 4, 2026 that may be closed by this pull request
1 task
@cbagwell cbagwell deleted the docker-work-port-fix branch May 6, 2026 16:10
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.

[Bug]: App View never worked for me, and Browser view rarely works. [App tab] Improve ability for Agent to use the App tab

3 participants