You want to run Qwen7B inside a Docker container for portability and isolation but are unsure about setting up Ollama within the container.
Define a Dockerfile to install Ollama and set up Qwen7B inside a container.
# Use an Ubuntu base image
FROM ubuntu:22.04
# Set environment variables to prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
# Install dependencies
RUN apt update && apt install -y curl
# Install Ollama
RUN curl -fsSL https://ollama.com/install.sh | sh
# Download and preload the Qwen 7B model
RUN ollama pull qwen:7b
# Expose the port for API access (optional)
EXPOSE 11434
# Run Ollama as the default process
CMD ["ollama", "serve"]
Navigate to the directory where the Dockerfile is saved and build the image:
docker build -t qwen-7b-container .
This will create a Docker image named qwen-7b-container.
Run the container and start Ollama:
docker run --rm -it -p 11434:11434 qwen-7b-container
This starts the container and exposes Ollama’s API on port 11434.
Now that the container is running, you can execute prompts from outside the container using:
ollama run qwen:7b "Tell me about black holes."
OR, send a request via curl :
curl http://localhost:11434/api/generate -d '{
"model": "qwen:7b",
"prompt": "Explain quantum mechanics in simple terms"
}'
There are servral model sizes, including 0.5B, 1.8B, 4B (default), 7B, 14B, 32B (new) and 72B. If you want to test another model replace tag 7b in the Dockerfile with the required model as mentioned here. Also see the size of model in below table.
Running Qwen 7B in a Docker container provides portability, isolation, and easy deployment across multiple environments. You can now interact with the AI model using local commands or API requests.
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our AI/ML Expertise.
0