[GH-ISSUE #3365] Unable to make cors work in docker container #2069

Closed
opened 2026-04-12 12:18:22 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @gbarton on GitHub (Mar 27, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/3365

What is the issue?

I have been trying to get cors to work inside a docker container with no luck so far. Attached is my docker-compose.yaml for starting ollama. I have tried many variations on the OLLAMA_HOST and OLLAMA_ORIGINS env vars to no luck. Does anyone know the magic combo to make it work?

What did you expect to see?

hitting it from a browser directly works fine, from code works fine, using Ollama chats https://github.com/drazdra/ollama-chats hosted on another node runs into cors fun:

image

curling on the local box shows anything set as origin is blocked:

gman@ai:~/wrk/ai-runtime$ curl -i -H 'Origin:http://10.22.22.1' localhost:11434/
HTTP/1.1 403 Forbidden
Date: Wed, 27 Mar 2024 03:20:24 GMT
Content-Length: 0

gman@ai:~/wrk/ai-runtime$ curl localhost:11434
Ollama is running

Steps to reproduce

docker-compose.yaml

version: '3.6'

services:
  ollama:
    container_name: ollama
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    image: ollama/ollama
      #tty: true
    restart: unless-stopped
    environment:
    - OLLAMA_ORIGINS="*"
    - OLLAMA_HOST="0.0.0.0:11434"
    ports:
      - 11434:11434
    volumes:
      - ./ollama:/root/.ollama:cached

Are there any recent changes that introduced the issue?

No response

OS

Linux

Architecture

amd64

Platform

Docker

Ollama version

0.1.29

GPU

Nvidia

GPU info

No response

CPU

AMD

Other software

No response

Originally created by @gbarton on GitHub (Mar 27, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/3365 ### What is the issue? I have been trying to get cors to work inside a docker container with no luck so far. Attached is my docker-compose.yaml for starting ollama. I have tried many variations on the OLLAMA_HOST and OLLAMA_ORIGINS env vars to no luck. Does anyone know the magic combo to make it work? ### What did you expect to see? hitting it from a browser directly works fine, from code works fine, using Ollama chats https://github.com/drazdra/ollama-chats hosted on another node runs into cors fun: ![image](https://github.com/ollama/ollama/assets/1878953/fea70cec-b52a-441a-b163-d9bf23b6af99) curling on the local box shows anything set as origin is blocked: ```bash gman@ai:~/wrk/ai-runtime$ curl -i -H 'Origin:http://10.22.22.1' localhost:11434/ HTTP/1.1 403 Forbidden Date: Wed, 27 Mar 2024 03:20:24 GMT Content-Length: 0 gman@ai:~/wrk/ai-runtime$ curl localhost:11434 Ollama is running ``` ### Steps to reproduce docker-compose.yaml ``` version: '3.6' services: ollama: container_name: ollama deploy: resources: reservations: devices: - driver: nvidia count: 1 capabilities: [gpu] image: ollama/ollama #tty: true restart: unless-stopped environment: - OLLAMA_ORIGINS="*" - OLLAMA_HOST="0.0.0.0:11434" ports: - 11434:11434 volumes: - ./ollama:/root/.ollama:cached ``` ### Are there any recent changes that introduced the issue? _No response_ ### OS Linux ### Architecture amd64 ### Platform Docker ### Ollama version 0.1.29 ### GPU Nvidia ### GPU info _No response_ ### CPU AMD ### Other software _No response_
GiteaMirror added the bug label 2026-04-12 12:18:22 -05:00
Author
Owner

@mxyng commented on GitHub (Mar 27, 2024):

This is a side effect of using Docker Compose's environment in list mode which passes the value verbatim.

Here's a minimal example:

With quotes; fails

version: '3'

services:
  ollama:
    image: ollama/ollama:latest
    environment:
      - OLLAMA_ORIGINS="*"
      - OLLAMA_HOST="0.0.0.0:11434"
    ports:
      - 11434:11434
$ curl -v -H Origin:http://10.22.22.1 localhost:11434
*   Trying [::1]:11434...
* Connected to localhost (::1) port 11434
> GET / HTTP/1.1
> Host: localhost:11434
> User-Agent: curl/8.4.0
> Accept: */*
> Origin:http://10.22.22.1
>
< HTTP/1.1 403 Forbidden
< Date: Wed, 27 Mar 2024 21:50:34 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact

Without quotes; succeeds

version: '3'

services:
  ollama:
    image: ollama/ollama:latest
    environment:
      - OLLAMA_ORIGINS=*
      - OLLAMA_HOST=0.0.0.0:11434
    ports:
      - 11434:11434
$ curl -v -H Origin:http://10.22.22.1 localhost:11434
*   Trying [::1]:11434...
* Connected to localhost (::1) port 11434
> GET / HTTP/1.1
> Host: localhost:11434
> User-Agent: curl/8.4.0
> Accept: */*
> Origin:http://10.22.22.1
>
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Content-Type: text/plain; charset=utf-8
< Date: Wed, 27 Mar 2024 22:26:09 GMT
< Content-Length: 17
<
* Connection #0 to host localhost left intact
Ollama is running
<!-- gh-comment-id:2024093077 --> @mxyng commented on GitHub (Mar 27, 2024): This is a side effect of using Docker Compose's `environment` in list mode which passes the value verbatim. Here's a minimal example: With quotes; fails ```yaml version: '3' services: ollama: image: ollama/ollama:latest environment: - OLLAMA_ORIGINS="*" - OLLAMA_HOST="0.0.0.0:11434" ports: - 11434:11434 ``` ``` $ curl -v -H Origin:http://10.22.22.1 localhost:11434 * Trying [::1]:11434... * Connected to localhost (::1) port 11434 > GET / HTTP/1.1 > Host: localhost:11434 > User-Agent: curl/8.4.0 > Accept: */* > Origin:http://10.22.22.1 > < HTTP/1.1 403 Forbidden < Date: Wed, 27 Mar 2024 21:50:34 GMT < Content-Length: 0 < * Connection #0 to host localhost left intact ``` Without quotes; succeeds ```yaml version: '3' services: ollama: image: ollama/ollama:latest environment: - OLLAMA_ORIGINS=* - OLLAMA_HOST=0.0.0.0:11434 ports: - 11434:11434 ``` ``` $ curl -v -H Origin:http://10.22.22.1 localhost:11434 * Trying [::1]:11434... * Connected to localhost (::1) port 11434 > GET / HTTP/1.1 > Host: localhost:11434 > User-Agent: curl/8.4.0 > Accept: */* > Origin:http://10.22.22.1 > < HTTP/1.1 200 OK < Access-Control-Allow-Origin: * < Content-Type: text/plain; charset=utf-8 < Date: Wed, 27 Mar 2024 22:26:09 GMT < Content-Length: 17 < * Connection #0 to host localhost left intact Ollama is running ```
Author
Owner

@gbarton commented on GitHub (Mar 27, 2024):

wow yup, that fixed it. Thank you so much!

<!-- gh-comment-id:2024108662 --> @gbarton commented on GitHub (Mar 27, 2024): wow yup, that fixed it. Thank you so much!
Author
Owner

@smit-io commented on GitHub (May 2, 2024):

Needs to be documented.

<!-- gh-comment-id:2089415151 --> @smit-io commented on GitHub (May 2, 2024): Needs to be documented.
Author
Owner

@drahnr commented on GitHub (Jul 31, 2025):

Even with the given patches applied, the env variable OLLAMA_ORIGINS="moz-extension://*" (with and without quotes, single and double) is not picked up by the container. The logs confirm this:

time=2025-07-31T11:23:43.826Z level=INFO source=routes.go:1235 msg="server config" env="map[ <.. SNIP ..> OLLAMA_ORIGINS:[http://localhost https://localhost http://localhost:* https://localhost:* http://127.0.0.1 https://127.0.0.1 http://127.0.0.1:* https://127.0.0.1:* http://0.0.0.0 https://0.0.0.0 http://0.0.0.0:* https://0.0.0.0:* app://* file://* tauri://* vscode-webview://* vscode-file://*]
<!-- gh-comment-id:3139545181 --> @drahnr commented on GitHub (Jul 31, 2025): Even with the given patches applied, the env variable `OLLAMA_ORIGINS="moz-extension://*"` (with and without quotes, single and double) is not picked up by the container. The logs confirm this: ``` time=2025-07-31T11:23:43.826Z level=INFO source=routes.go:1235 msg="server config" env="map[ <.. SNIP ..> OLLAMA_ORIGINS:[http://localhost https://localhost http://localhost:* https://localhost:* http://127.0.0.1 https://127.0.0.1 http://127.0.0.1:* https://127.0.0.1:* http://0.0.0.0 https://0.0.0.0 http://0.0.0.0:* https://0.0.0.0:* app://* file://* tauri://* vscode-webview://* vscode-file://*] ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#2069