AI/ML

Deploying DeepSeek-R1 8B in Docker with Ollama: A Complete Setup Guide


Problem

You want to run Deepseek-r1 8B inside a Docker container for portability and isolation but are unsure about setting up Ollama within the container.

Solution

  • Create a Dockerfile to install Ollama inside a container.

  • Pull and run Deepseek-r1 8B inside the container.

  • Allow the container to interact with the host system for efficient execution.

 

1. Create a Dockerfile

Define a Dockerfile to install Ollama and set up Deepseek-r1 8B inside a container.

# Use an Ubuntu base imageFROM ubuntu:22.04  # Set environment variables to prevent interactive promptsENV DEBIAN_FRONTEND=noninteractive  # Install dependenciesRUN apt update && apt install -y curl  # Install OllamaRUN curl -fsSL https://ollama.com/install.sh | sh  # Download and preload the Deepseek-r1 8B modelRUN ollama pull deepseek-r1:8b  # Expose the port for API access (optional)EXPOSE 11434  # Run Ollama as the default processCMD ["ollama", "serve"]

2. Build the Docker Image

Navigate to the directory where the Dockerfile is saved and build the image:

docker build -t deepseek-r1-container .

 

This will create a Docker image named deepseek-r1-container.

3. Run the Container

Run the container and start Ollama:

docker run --rm -it -p 11434:11434 deepseek-r1-container

 

This starts the container and exposes Ollama’s API on port 11434.

4. Interact with Deepseek from the Host

Now that the container is running, you can execute prompts from outside the container using:  

ollama run deepseek-r1:8b "Tell me about black holes."

 

OR, send a request via curl :

curl http://localhost:11434/api/generate -d '{  "model": "deepseek-r1:8b",  "prompt": "Explain quantum mechanics in simple terms"}' 

What’s Next for DeepSeek AI?

Running Deepseek-r1 8B 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