[GH-ISSUE #1829] access api from docker container #1042

Closed
opened 2026-04-12 10:46:39 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @robertsmaoui on GitHub (Jan 6, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/1829

Hello, docker containers cannot access to http://127.0.0.1:11434/api/chat

so i installed docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama

it works using docker exec -it ollama ollama run llama2

but i want using as API, it is possible , base url ??

Thanks

Originally created by @robertsmaoui on GitHub (Jan 6, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/1829 Hello, docker containers cannot access to http://127.0.0.1:11434/api/chat so i installed docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama it works using docker exec -it ollama ollama run llama2 but i want using as API, it is possible , base url ?? Thanks
Author
Owner

@jimscard commented on GitHub (Jan 7, 2024):

Hi, it would be better to ask questions like this in the discord.

It looks like your docker run command is constructed incorrectly. Did it not throw an error?

The first argument of the -v flag is not in the correct format. It should be in the format of "host-path:container-path". In this case, it seems like you want to map a local folder called "ollama" to the container's "/root/.ollama" folder. If that's the case, the correct format would be:

-v /path/to/local/ollama:/root/.ollama

Also, you may need to pull the image first, e.g.

docker pull ollama/ollama

Then, you're going to need a model to use. I started with an empty "ollama" folder, so I connected to the terminal session in the running container via Docker Dashboard, and pulled a model, e.g.,

ollama pull tinyllama

Then I could access and use the API from my laptop's CLI, I tested using curl, e.g.,

curl -X POST http://localhost:11434/api/generate -d '{
  "model": "tinyllama",
  "prompt":"Here is a story about llamas eating grass"
 }'
<!-- gh-comment-id:1879917912 --> @jimscard commented on GitHub (Jan 7, 2024): Hi, it would be better to ask questions like this in the [discord](https://discord.gg/bduDybW3). It looks like your docker run command is constructed incorrectly. Did it not throw an error? The first argument of the -v flag is not in the correct format. It should be in the format of "host-path:container-path". In this case, it seems like you want to map a local folder called "ollama" to the container's "/root/.ollama" folder. If that's the case, the correct format would be: ``` -v /path/to/local/ollama:/root/.ollama ``` Also, you may need to pull the image first, e.g. ``` docker pull ollama/ollama ``` Then, you're going to need a model to use. I started with an empty "ollama" folder, so I connected to the terminal session in the running container via Docker Dashboard, and pulled a model, e.g., ``` ollama pull tinyllama ``` Then I could access and use the API from my laptop's CLI, I tested using curl, e.g., ``` curl -X POST http://localhost:11434/api/generate -d '{ "model": "tinyllama", "prompt":"Here is a story about llamas eating grass" }' ```
Author
Owner

@jinnabaalu commented on GitHub (Jan 7, 2024):

  • I created a docker-compose.yml Created the PR with the same docker-compose

  • Running as the container in the daemon mode with docker-compose up -d

  • Post the model with API

curl -X POST http://localhost:11434/api/generate -d '{
  "model": "tinyllama",
  "prompt":"Here is a story about llamas eating grass"
 }'
<!-- gh-comment-id:1880062039 --> @jinnabaalu commented on GitHub (Jan 7, 2024): - I created a docker-compose.yml Created the [PR](https://github.com/jmorganca/ollama/pull/1840) with the same docker-compose - Running as the container in the daemon mode with `docker-compose up -d` - Post the model with API ```bash curl -X POST http://localhost:11434/api/generate -d '{ "model": "tinyllama", "prompt":"Here is a story about llamas eating grass" }' ```
Author
Owner

@mxyng commented on GitHub (Jan 8, 2024):

@robertsmaoui I'm not sure what issues you're experiencing. The commands you provided should work as you'd expect.

$ docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
a28f0d7934d3c96066a70937fc1b99d280b37653b423d6e45e31f82ce0951087
$ curl -v localhost:11434/api/version
*   Trying [::1]:11434...
* Connected to localhost (::1) port 11434
> GET /api/version HTTP/1.1
> Host: localhost:11434
> User-Agent: curl/8.4.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Date: Mon, 08 Jan 2024 19:10:37 GMT
< Content-Length: 20
<
* Connection #0 to host localhost left intact
{"version":"0.1.18"}
$ ollama --version
ollama version is 0.1.18
<!-- gh-comment-id:1881672895 --> @mxyng commented on GitHub (Jan 8, 2024): @robertsmaoui I'm not sure what issues you're experiencing. The commands you provided should work as you'd expect. ``` $ docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama a28f0d7934d3c96066a70937fc1b99d280b37653b423d6e45e31f82ce0951087 $ curl -v localhost:11434/api/version * Trying [::1]:11434... * Connected to localhost (::1) port 11434 > GET /api/version HTTP/1.1 > Host: localhost:11434 > User-Agent: curl/8.4.0 > Accept: */* > < HTTP/1.1 200 OK < Content-Type: application/json; charset=utf-8 < Date: Mon, 08 Jan 2024 19:10:37 GMT < Content-Length: 20 < * Connection #0 to host localhost left intact {"version":"0.1.18"} $ ollama --version ollama version is 0.1.18 ```
Author
Owner

@jankogasic commented on GitHub (Feb 3, 2025):

@robertsmaoui I had the same issue and what solved it for me is using hostname instead of localhost. You can retrieve it on Linux by executing hostname in terminal.

<!-- gh-comment-id:2630947250 --> @jankogasic commented on GitHub (Feb 3, 2025): @robertsmaoui I had the same issue and what solved it for me is using hostname instead of `localhost`. You can retrieve it on Linux by executing `hostname` in terminal.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#1042