[GH-ISSUE #4237] Get a random available port #80323

Closed
opened 2026-05-09 08:44:35 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @robbycbennett on GitHub (May 7, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/4237

This would be perfect for making Ollama a child process.

Here's what this may look like:

  1. The parent process starts
  2. The parent process does a command like env OLLAMA_HOST=localhost:random ollama serve
  3. The child process ollama gets a random available port from the OS and outputs the port number to stdout. Otherwise, it crashes.
Originally created by @robbycbennett on GitHub (May 7, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/4237 This would be perfect for making Ollama a child process. Here's what this may look like: 1. The parent process starts 2. The parent process does a command like `env OLLAMA_HOST=localhost:random ollama serve` 3. The child process `ollama` gets a random available port from the OS and outputs the port number to stdout. Otherwise, it crashes.
GiteaMirror added the feature request label 2026-05-09 08:44:35 -05:00
Author
Owner

@mxyng commented on GitHub (May 7, 2024):

This is already possible if you set OLLAMA_HOST=:0

$ OLLAMA_HOST=:0 ollama serve 2>&1 | grep -e 'Listening on'
time=2024-05-07T13:30:07.280-07:00 level=INFO source=routes.go:1029 msg="Listening on [::]:64939 (version 0.0.0)"
<!-- gh-comment-id:2099251535 --> @mxyng commented on GitHub (May 7, 2024): This is already possible if you set `OLLAMA_HOST=:0` ``` $ OLLAMA_HOST=:0 ollama serve 2>&1 | grep -e 'Listening on' time=2024-05-07T13:30:07.280-07:00 level=INFO source=routes.go:1029 msg="Listening on [::]:64939 (version 0.0.0)" ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#80323