I am trying to implement a Chainlit app that needs to access a Qdrant server, and is managed with UV. I use qdrant/qdrant as the base model in my dockerfile, then I import UV. In order to start Qdrant before trying to run my app, I use an entrypoint instead of cmd.
When I run the app directly on my desktop, with an already running Qdrant server, it works fine. When I build and run the dockerfile locally, it runs perfectly. But when I push the code back to Hugging Face, Qdrant starts up but the UV command is not visible.
Dockerfile:
# Trying to put qdrant into same container as chainlit application
# Start with qdrant image
FROM qdrant/qdrant:latest
# Need curl and ca-certificates
RUN apt-get update && apt-get install -y \
--no-install-recommends curl ca-certificates\
&& rm -rf /var/lib/apt/lists/*
# Install uv
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh
# Set te home directory and path
ENV HOME=/home/user \
PATH="/home/user/.local/bin:/root/.local/bin/:$PATH"
# # NEEDED FOR CHAINLIT IN HUGGING FACE SPACES
ENV UVICORN_WS_PROTOCOL=websockets
# # Set the working directory
WORKDIR $HOME/app
# # Copy the app to the container
COPY --chown=user . $HOME/app
RUN chmod 777 entrypoint.sh
# # Install the dependencies
RUN uv sync --frozen
# # Expose the ports
EXPOSE 7860 6333
ENTRYPOINT ["./entrypoint.sh"]
entrypoint.sh:
#!/bin/bash
# Start Qdrant in the background
echo "Starting Qdrant server..."
/qdrant/qdrant &
# Run my chainlit app using uv
echo "Starting Chainlit application..."
uv run chainlit run app.py --host 0.0.0.0 --port 7860
Output in HF Space:
===== Application Startup at 2025-01-07 18:47:56 =====
Starting Qdrant server...
Starting Chainlit application...
./entrypoint.sh: line 8: uv: command not found
I changed some things and got interesting information. In the Dockerfile:
ENV PATH="/root/.local/bin:$PATH"
and the script:
#!/bin/bash
echo "Current directory: $(pwd)"
echo "Current path: $PATH"
directory="../root/.local/bin"
if [ -d "$directory" ];
then
echo "Directory exists: $directory"
echo "Files in $directory:"
find "$directory" -type f
else
echo "Directory does not exist: $directory"
fi
When I create a Docker container and run it on my desktop using Desktop Docker, I see the following:
Current directory: /app
2025-01-08 11:15:05 Current path: /root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
2025-01-08 11:15:05 Directory exists: ../root/.local/bin
2025-01-08 11:15:05 Files in ../root/.local/bin:
2025-01-08 11:15:05 ../root/.local/bin/uvx
2025-01-08 11:15:05 ../root/.local/bin/env.fish
2025-01-08 11:15:05 ../root/.local/bin/env
2025-01-08 11:15:05 ../root/.local/bin/uv
When I push to Hugging Face I see this:
Current directory: /app
Current path: /root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Directory does not exist: ../root/.local/bin
There are various unique restrictions on Docker Spaces for HF, but to put it briefly, you should assume that, in principle, you can only access the app/ directory and below after starting up.
For example, if you need to modify the Python system directory during installation, you’ll need to use a rather roundabout method to get it to work. Or you won’t be able to do it at all.
When the things we’ve brought over from github don’t work smoothly, it’s usually because of the above problem or because the model file is too large and it’s caught by the recent Spaces git restriction (1GB).
So in my Dockerfile, having installed UV (which later executes in the Dockerfile stage) in root/.local/bin, I could copy the uv components into the /app directory, and then hit uv in the app directory?
Maybe. I don’t know if uv will work in that state, but if it doesn’t matter where you put it, then it should be fine. You can also call it from Python using subprocess or system.
As long as we don’t touch the system directory or libraries that are implicitly prohibited, we can do most things freely. There are generally fewer restrictions after startup than during startup.