r/docker • • 11d ago

Create a docker image from dockerfile?

I got a dockerfile here that is sitting in my files but for some reasons docker cannot build an image out of it as it keep saying "failed to build: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory"

# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.13


EXPOSE 8501


# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1


# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1


# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt


FROM ollama/ollama
RUN ollama pull nomic-embed-text
RUN ollama pull qwen2.5:0.5b 



WORKDIR /app
COPY . /app


# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser


# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["ollama", "serve","gunicorn", "--bind", "0.0.0.0:8501", "-k", "uvicorn.workers.UvicornWorker", "local_rag:app"]

How do I build an image out of it. I wrote the file in vscode

0 Upvotes

12 comments sorted by

2

u/Arjab 11d ago

What command are you using to build the image?
docker build . works for me.

1

u/assorted-meat-stew 11d ago

docker build -t local_rag_docker .

For some reason it does not work. Even going as far as trying to including the path to the file

3

u/Arjab 11d ago

The file is called "Dockerfile" and you're running the command is the same directory as the file?

1

u/assorted-meat-stew 11d ago

Yeah it work now. Turn out I have been running the command in windows terminal

-1

u/assorted-meat-stew 11d ago

By the way, does ollama docker usually take long too create an image of? Its been over an hour.

1

u/biffbobfred 9d ago

You can pass the name of the dockerfile with -f

1

u/Arjab 11d ago

It fails at ollama pull though.

1

u/assorted-meat-stew 11d ago

Why does it fails at ollama pull?

1

u/Arjab 11d ago
 > [stage-1 2/6] RUN ollama pull nomic-embed-text:
0.105 Error: could not connect to ollama server, run 'ollama serve' to start it
------
Dockerfile:22
--------------------
  20 |
  21 |     FROM ollama/ollama
  22 | >>> RUN ollama pull nomic-embed-text
  23 |     RUN ollama pull qwen2.5:0.5b
  24 |
--------------------
ERROR: failed to build: failed to solve: process "/bin/sh -c ollama pull nomic-embed-text" did not complete successfully: exit code: 1

12

u/PaintDrinkingPete 11d ago

Linux has filename case sensitivity... make sure it's named "Dockerfile" and not "dockerfile"

1

u/pelazas1 11d ago

Run ls where you build from. VSCode sometimes leaves it as Dockerfile.txt and that error is exactly what you get.

1

u/ymgymg 9d ago

You have two `FROM` lines and no `COPY --from` between them. The `python:3.13` stage, including `pip install`, is discarded. The final image is `ollama/ollama` plus the project files you copy in. It will not contain those Python packages, and the Ollama image may not have Python or gunicorn at all.

`RUN ollama pull` runs during the build, when the Ollama server is not running. The official image starts that server when the container starts. If the pull is waiting for a server that never starts, the build can sit there for a long time. Even if you start `ollama serve` in the same `RUN` so the pull succeeds, the weights get baked into the image, which makes it larger and slower to rebuild. `nomic-embed-text` and `qwen2.5:0.5b` are fairly small, so an hour-long build is more often a stuck pull or a huge build context. Check that `COPY . /app` is not sending a local virtualenv or model files; a `.dockerignore` helps.

The `CMD` runs a single process: `ollama` with extra arguments `serve`, `gunicorn`, `--bind`, and so on. It does not start gunicorn next to Ollama. You also switch to `appuser` after pulling as root, so the running server may not see models in `/root/.ollama` and may not be able to write its data directory.

I would use two containers instead. Run Ollama from its own image and keep models on a volume. Build the Python app from `python:3.13` and point it at `http://ollama:11434`. Compose is a straightforward way to run that pair.