-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(MacOS) Ports are not available: 5900 #147
Comments
Fixes anthropics#147 Implement dynamic port allocation to avoid conflicts with reserved ports. * **computer-use-demo/image/x11vnc_startup.sh** - Add functions to check port availability and find an available port. - Dynamically assign the VNC server port instead of hardcoding port 5900. - Update the `netstat` command to use the dynamically assigned port. * **computer-use-demo/image/novnc_startup.sh** - Add functions to check port availability and find an available port. - Dynamically assign the VNC server port instead of hardcoding port 5900. - Modify the `--vnc` option to use the dynamic port. * **computer-use-demo/image/port_check.sh** - Create a script to check port availability. - Use `lsof` to check if a port is in use. - Return an available port if the specified one is in use. * **computer-use-demo/.ports** - Maintain a list of reserved ports. - Include common ports used by macOS and other systems. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/anthropics/anthropic-quickstarts/issues/147?shareId=XXXX-XXXX-XXXX-XXXX).
Ok, so here's what I've done. pi@πlocal ~/demeisen_gen2/computer-use-demo main
> cat .ports
# INTERNAL ports end in 1 (think 1 ~ I for Internal), EXTERNAL ports end in 0
PORT_VNC_INTERNAL=5901
PORT_VNC_EXTERNAL=5900
PORT_NOVNC_INTERNAL=6081
PORT_NOVNC_EXTERNAL=6080
PORT_HTTP_INTERNAL=8081
PORT_HTTP_EXTERNAL=8080
PORT_STREAMLIT_INTERNAL=8501
PORT_STREAMLIT_EXTERNAL=8500 And I've tweaked pi@πlocal ~/demeisen_gen2/computer-use-demo main
> cat image/entrypoint.sh
#!/bin/bash
set -e
# Source and export all variables from .ports
set -a
source /host/computer-use-demo/.ports || exit 1
set +a
./start_all.sh
./novnc_startup.sh
# Generate index.html from template
envsubst < static_content/index.html.template > static_content/index.html
: Now, as all these port variables are now in the shell environment, the subservient ?_startup.sh scripts can all use them, as can any Python script. The only gotcha is that static_content/index.html uses a port, so I've moved that to a .template file, which entrypoint.sh renders (as you can see above). Another benefit of what I've done is to separate EXTERNAL from INTERNAL ports. That's important for code-clarity, otherwise you have two separate objects that happen to have the same value only being referenced by that value. Confusing. Finally grep for all the 4 hardcoded initial ports to make sure you've replaced EVERY SINGLE HARDCODED reference, and you should be good to go. There's one gotcha though. Does this .ports go INTO the docker image via COPY in the Dockerfile? For me no, as I'm mounting the containing host-folder, so that the container can see its self. |
- Add .ports configuration file for clean port mapping - Separate internal from external ports - Add port availability validation - Update all components to use configured ports - Add gettext-base for template processing This change prevents port conflicts when running multiple instances and provides a cleaner separation between internal and external ports. Fixes anthropics#147
- Check for existing container ports (Streamlit/NoVNC) - Add helpful warning with docker commands - Auto-retry for commonly conflicting ports (VNC/HTTP) - Continue execution to allow multiple instances Related to anthropics#147
Hmm, I have screen sharing off on my Mac, and still get this error. |
ok fixed it by:
full cmd:
|
Running this command stopped the Mac service that uses the port for me. |
Executing the (minimally tweaked)
docker run
command from the README.md:Inspecting, ...
It turns out that I have to disable screen-sharing on macOS to free this port:
I think it's a mistake to re-use a port that macOS has, by default, reserved, given that you are free to use ANY port you wish.
It does seem odd to me that in 2024 the best solution still seems to be "Pick a random 16-bit integer and hope nobody else on your OS picked the same one". Very retro. hey ho...
I think it would make much more sense to have a .ports file and make the ports dynamic. And to use different numbers for external and internal. That would make the code easier to work with.
The text was updated successfully, but these errors were encountered: