Skip to content

fix(computer-use): make Docker ports configurable via environment variables#373

Open
gn00295120 wants to merge 2 commits into
anthropics:mainfrom
gn00295120:fix/configurable-docker-ports
Open

fix(computer-use): make Docker ports configurable via environment variables#373
gn00295120 wants to merge 2 commits into
anthropics:mainfrom
gn00295120:fix/configurable-docker-ports

Conversation

@gn00295120
Copy link
Copy Markdown

Summary

Replaces hardcoded port numbers with environment variables so the WebUI works correctly with custom Docker port mappings.

Quickstart

  • Computer Use Demo

Type of Change

  • Bug fix

Problem

When users map Docker ports asymmetrically (e.g. -p 9090:8080), the WebUI breaks because iframe URLs and service bindings use hardcoded port numbers (8080, 8501, 5900, 6080).

Solution

Introduce environment variables for all ports:

Variable Default Controls
HTTP_PORT 8080 Landing page HTTP server
STREAMLIT_PORT 8501 Streamlit app
VNC_PORT 5900 x11vnc server
NOVNC_PORT 6080 noVNC websocket proxy
HTTP_HOST_PORT = HTTP_PORT Host-side port for browser URLs
STREAMLIT_HOST_PORT = STREAMLIT_PORT Host-side Streamlit port
NOVNC_HOST_PORT = NOVNC_PORT Host-side noVNC port

The *_HOST_PORT variants are only needed for asymmetric mappings. The landing page index.html is regenerated at startup with correct host-side ports.

Usage

# Symmetric (works as before, no changes needed)
docker run -p 8080:8080 -p 5900:5900 -p 6080:6080 -p 8501:8501 ...

# Asymmetric (now works correctly)
docker run -p 9090:8080 -p 9501:8501 -p 9080:6080 \
  -e HTTP_HOST_PORT=9090 \
  -e STREAMLIT_HOST_PORT=9501 \
  -e NOVNC_HOST_PORT=9080 ...

Files Changed

File Change
Dockerfile Add ENV declarations with defaults
image/entrypoint.sh Read env vars, generate index.html at startup
image/http_server.py Use HTTP_PORT from env
image/x11vnc_startup.sh Use VNC_PORT from env
image/novnc_startup.sh Use VNC_PORT/NOVNC_PORT from env
image/index.html Add note about runtime regeneration
README.md Document custom port configuration

Fixes #271

Copilot AI review requested due to automatic review settings March 12, 2026 03:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the Computer Use Demo WebUI breaking under asymmetric Docker port mappings by making the container’s internal service ports and the browser-facing (host) ports configurable via environment variables, and regenerating the landing page at startup with the correct host-side ports.

Changes:

  • Introduces *_PORT and *_HOST_PORT environment variables and uses them across startup scripts.
  • Regenerates the landing page index.html at container startup to embed the correct host-side iframe URLs.
  • Updates docs to explain custom port mapping configuration.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
computer-use-demo/Dockerfile Adds default ENV values for the new port configuration variables.
computer-use-demo/image/entrypoint.sh Exports port env defaults and regenerates static_content/index.html with host-side ports.
computer-use-demo/image/http_server.py Binds the HTTP server to HTTP_PORT from the environment.
computer-use-demo/image/x11vnc_startup.sh Uses VNC_PORT env var for x11vnc bind and readiness check.
computer-use-demo/image/novnc_startup.sh Uses VNC_PORT/NOVNC_PORT env vars for noVNC and readiness check.
computer-use-demo/image/index.html Adds a note about runtime regeneration (but see review comment re: which file is actually regenerated/served).
computer-use-demo/README.md Documents how to use the new port environment variables for different mapping scenarios.
Comments suppressed due to low confidence (1)

computer-use-demo/image/novnc_startup.sh:21

  • The wait loop doesn’t verify that noVNC actually started: if the timeout elapses, the script will still continue and later print a success message. Consider checking timeout == 0 after the loop and exiting non-zero (optionally printing /tmp/novnc.log) when noVNC fails to bind.
timeout=10
while [ $timeout -gt 0 ]; do
    if netstat -tuln | grep -q ":${NOVNC_PORT} "; then
        break
    fi
    sleep 1
    ((timeout--))

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread computer-use-demo/image/index.html
Comment thread computer-use-demo/image/http_server.py
Comment thread computer-use-demo/image/entrypoint.sh
Comment thread computer-use-demo/README.md
@gn00295120 gn00295120 force-pushed the fix/configurable-docker-ports branch from 84d269d to e1b2b71 Compare March 12, 2026 05:19
gn00295120 added 2 commits May 2, 2026 22:19
…iables

Replace hardcoded port numbers (8080, 8501, 5900, 6080) with
environment variables (HTTP_PORT, STREAMLIT_PORT, VNC_PORT, NOVNC_PORT).

Add HOST_PORT variants (HTTP_HOST_PORT, STREAMLIT_HOST_PORT,
NOVNC_HOST_PORT) for asymmetric Docker port mappings where the
host port differs from the container port.

The landing page index.html is now regenerated at container startup
with the correct host-side port numbers so iframe URLs resolve
correctly regardless of Docker port mapping.

Fixes anthropics#271
@gn00295120 gn00295120 force-pushed the fix/configurable-docker-ports branch from e1b2b71 to 763843d Compare May 2, 2026 14:19
@gn00295120
Copy link
Copy Markdown
Author

@scutuatua-crypto can you check again ?

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.

Launching Docker container with Custom Ports makes WebUI unusable

3 participants