Allowing for an alternate port
This commit is contained in:
@@ -10,6 +10,7 @@ cd "$(dirname "$0")"
|
||||
[ -f .ai-config ] || { echo "No .ai-config yet - run ./setup.sh first." >&2; exit 1; }
|
||||
# shellcheck disable=SC1091
|
||||
source .ai-config
|
||||
PORT=${AI_PORT:-$PORT} # override for one run: AI_PORT=11500 ./run-ai-image.sh
|
||||
|
||||
running() { [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null)" = "true" ]; }
|
||||
exists() { docker inspect "$CONTAINER_NAME" >/dev/null 2>&1; }
|
||||
@@ -28,6 +29,12 @@ if running; then
|
||||
echo "Already running on http://127.0.0.1:$PORT"
|
||||
else
|
||||
exists && docker rm -f "$CONTAINER_NAME" >/dev/null
|
||||
if (exec 3<>"/dev/tcp/127.0.0.1/$PORT") 2>/dev/null; then
|
||||
echo "Port $PORT is already in use by something else (a host Ollama, another container?):" >&2
|
||||
docker ps --filter "publish=$PORT" --format ' container {{.Names}}' >&2 || true
|
||||
echo "Re-run ./setup.sh to pick a free port, or use: AI_PORT=<free port> ./run-ai-image.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
args=(-d --name "$CONTAINER_NAME" -p "127.0.0.1:$PORT:11434" --restart unless-stopped)
|
||||
[ "$USE_GPU" = "1" ] && args+=(--gpus all)
|
||||
docker run "${args[@]}" "$IMAGE_NAME" >/dev/null
|
||||
|
||||
Reference in New Issue
Block a user