[GH-ISSUE #2932] Start specific model from docker-compose #1797

Closed
opened 2026-04-12 11:50:17 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @donnadulcinea on GitHub (Mar 5, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/2932

Hello everybody. I am stuck with this issue. maybe many of you already faced and solved this.
This is my service in docker-compose:

  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    ports:
      - "11435:11434"
    volumes:
      - ./DockerVolumes/vol_ollama:/root/.ollama

I want the container to start with the llava model already without the need for me to connect to the shell and run it.
Which way can I do it? So far I tried adding the command statement, e.g.

command: ["ollama run llava:13b"]

or

command: ["/bin/sh", "-c", "/usr/bin/ollama run llava:13b"]

But I always receive errors like:

2024-03-05 19:07:44 Error: unknown command "ollama" for "ollama"

or

2024-03-05 19:07:44 Error: unknown command "/bin/sh" for "ollama"

Which way to achieve this?

Originally created by @donnadulcinea on GitHub (Mar 5, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/2932 Hello everybody. I am stuck with this issue. maybe many of you already faced and solved this. This is my service in docker-compose: ``` ollama: image: ollama/ollama:latest container_name: ollama ports: - "11435:11434" volumes: - ./DockerVolumes/vol_ollama:/root/.ollama ``` I want the container to start with the **llava** model already without the need for me to connect to the shell and run it. Which way can I do it? So far I tried adding the `command `statement, e.g. command: ["ollama run llava:13b"] or command: ["/bin/sh", "-c", "/usr/bin/ollama run llava:13b"] But I always receive errors like: 2024-03-05 19:07:44 Error: unknown command "ollama" for "ollama" or 2024-03-05 19:07:44 Error: unknown command "/bin/sh" for "ollama" Which way to achieve this?
Author
Owner

@remy415 commented on GitHub (Mar 5, 2024):

Hello,

First, the docker container is meant to containerize the ollama serve function, which will run it as a service. You shouldn't set the command as it will already run ollama serve by default. You also need to download the binary if you intend on using it as a front end (i.e. ollama run <model>), which is done outside of the container. In other words, they are two different functions.

<!-- gh-comment-id:1979667932 --> @remy415 commented on GitHub (Mar 5, 2024): Hello, First, the docker container is meant to containerize the `ollama serve` function, which will run it as a service. You shouldn't set the `command` as it will already run `ollama serve` by default. You also need to download the binary if you intend on using it as a front end (i.e. `ollama run <model>`), which is done outside of the container. In other words, they are two different functions.
Author
Owner

@remy415 commented on GitHub (Mar 5, 2024):

@donnadulcinea I forgot to mention:

I want the container to start with the llava model already without the need for me to connect to the shell and run it.

The Ollama service backend doesn't choose the models, it's the front-end that chooses it. If you are connecting via a JS or Python API, you would specify the model in the API call; if you're using ollama run <model>, you just run that command from CLI with the container running in the background. I hope that helps.

<!-- gh-comment-id:1979671201 --> @remy415 commented on GitHub (Mar 5, 2024): @donnadulcinea I forgot to mention: > I want the container to start with the llava model already without the need for me to connect to the shell and run it. The Ollama service backend doesn't choose the models, it's the front-end that chooses it. If you are connecting via a JS or Python API, you would specify the model in the API call; if you're using `ollama run <model>`, you just run that command from CLI with the container running in the background. I hope that helps.
Author
Owner

@donnadulcinea commented on GitHub (Mar 6, 2024):

@remy415 Thank you it is perfectly clear.
I can select and start the model directly through the APIs.

<!-- gh-comment-id:1979937819 --> @donnadulcinea commented on GitHub (Mar 6, 2024): @remy415 Thank you it is perfectly clear. I can select and start the model directly through the APIs.
Author
Owner

@talyguryn commented on GitHub (Mar 24, 2025):

Updating the command doesn't work because of settings of two last layers of ollama:

ENTRYPOINT ["/bin/ollama"]
CMD ["serve"]

Not the best solution, but I decided to update the entrypoint and it works good enough.

services:
  ollama:
    image: ollama/ollama:latest
    entrypoint:
      [
        "/bin/bash",
        "-c",
        "ollama serve & sleep 5 && ollama pull deepseek-r1:1.5b && wait",
      ]
    environment:
      - OLLAMA_KEEP_ALIVE="24h"
    volumes:
      - ollama-storage:/root/.ollama
    ports:
      - "11434:11434"
    restart: unless-stopped

https://github.com/talyguryn/ollama-and-open-webui/

<!-- gh-comment-id:2749194836 --> @talyguryn commented on GitHub (Mar 24, 2025): Updating the command doesn't work because of settings of two last layers of ollama: ``` ENTRYPOINT ["/bin/ollama"] CMD ["serve"] ``` Not the best solution, but I decided to update the entrypoint and it works good enough. ``` services: ollama: image: ollama/ollama:latest entrypoint: [ "/bin/bash", "-c", "ollama serve & sleep 5 && ollama pull deepseek-r1:1.5b && wait", ] environment: - OLLAMA_KEEP_ALIVE="24h" volumes: - ollama-storage:/root/.ollama ports: - "11434:11434" restart: unless-stopped ``` https://github.com/talyguryn/ollama-and-open-webui/
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#1797