Skip to content

Docker for Neural Networks

Briefly

Docker allows you to package a neural network or AI service into a container and run it consistently on any machine. It's like a 'box' where everything is already set up: Python, libraries, model, and environment.

Why Use Docker in AI Projects

Typically, AI tools require many dependencies: Python, PyTorch, CUDA, system libraries. Docker solves this pain:

  • Consistent for everyone: works on your machine and on the server;
  • Isolation: the environment does not conflict with other projects;
  • Cleanliness: remove the container and there is no garbage left on the host;
  • Convenience: one file docker-compose.yml raises a whole stack.

What It Looks Like

flowchart LR
    A[User] --> B[Open WebUI]
    B --> C[Ollama]
    C --> D[GPU or CPU]

Here are two containers:

  • Ollama — engine for running models;
  • Open WebUI — web interface for communicating with the model.

What to Install

  1. Docker Desktop — for Windows and macOS:

👉 https://www.docker.com/products/docker-desktop/

  1. For Linux — Docker Engine and Docker Compose.

  2. For GPU inference on Linux, additionally install NVIDIA Container Toolkit.

Windows

On Windows, it's easiest to start with the CPU version. Running GPU through Docker on Windows is usually done via WSL 2 and requires NVIDIA Container Toolkit inside WSL.

Basic Commands

Command What it does
docker ps show running containers
docker logs ollama view container logs
docker stop ollama stop container
docker compose up -d start stack in background
docker compose down stop and remove stack

Example: Ollama in Docker

Start Ollama:

docker run -d \
  --name ollama \
  -p 11434:11434 \
  -v ollama:/root/.ollama \
  ollama/ollama

Download the model inside the container:

docker exec -it ollama ollama run qwen2.5:1.5b

Now Ollama is listening on port 11434.

Example: Ollama + Open WebUI Stack

File docker-compose.yml:

services:
  ollama:
    image: ollama/ollama
    container_name: ollama
    ports:
      - "11434:11434"
    volumes:
      - ollama:/root/.ollama

  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: open-webui
    ports:
      - "3000:8080"
    environment:
      - OLLAMA_BASE_URL=http://ollama:11434
    volumes:
      - open-webui:/app/backend/data
    depends_on:
      - ollama

volumes:
  ollama:
  open-webui:

Start:

docker compose up -d

After this, open:

http://localhost:3000

What to Remember

  • The first start downloads images — this may take time.
  • Models are stored in volumes and do not disappear after a restart.
  • For production, add memory limits and monitoring.
  • Do not run containers with root permissions without necessity.

See Also