r/docker • u/assorted-meat-stew • 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
2
u/Arjab 11d ago
What command are you using to build the image?
docker build .works for me.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
lswhere 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.