Complete Guide to Deploying AI Agent Services with Docker on Windows and Linux

    This guide walks through a practical, cross-platform Docker workflow for running AI Agent services on Windows and Linux: environment setup, image pulls, persistent configuration, security, verification, and troubleshooting. You get a reproducible, maintainable container setup with consistent behavior across hosts.

    Background and goals

    As large language models become widely available, more teams want to run AI Agent services in containers for consistent environments, easier migration, and elastic scaling. Docker is the most common container runtime and has mature options on both Windows and Linux. This article covers an end-to-end, platform-agnostic practice: taking an AI Agent service from a clean host to a stable deployment.

    Overall goals:

    • Cross-platform consistency: the same image and configuration behave the same on Windows and Linux
    • Reproducibility: lock the process in config files and scripts so it is not “works on my machine”
    • Maintainability: separate logs, data, and config for upgrades and rollbacks
    • Security and control: run with least privilege; do not bake secrets into the image

    Environment setup

    1. Install the Docker engine

    • Linux: Use a current mainstream distribution, install Docker Engine via the system package manager, and add your user to the docker group so you do not need elevated privileges for every command:
    1. sudo usermod -aG docker $USER
    2. newgrp docker
    • Windows: Install Docker Desktop and enable the WSL 2 backend. WSL 2 provides a real Linux kernel, with better container compatibility and file I/O than the older Hyper-V approach.

    Verify the install:

    1. docker version
    2. docker info

    2. Resources and disk planning

    AI Agent services often depend on model inference. If you load models locally, plan ahead:

    • Memory: at least 8 GB available; 16 GB or more is recommended for local inference
    • Disk: images and model files can take several GB; reserve enough space for data directories
    • GPU (optional): for GPU inference, install GPU support for the container runtime and map devices when you start the container

    Pulling images and speeding up downloads

    1. Pull the official image

    After you identify the official image repository, run:

    1. docker pull <image-name>:latest

    In production, pin a specific tag instead of latest so upgrades are controlled and rollbacks are possible.

    2. Registry mirrors

    Pulling large images from remote registries can be slow or time out. A common approach is to configure a registry mirror in daemon.json:

    1. {
    2. "registry-mirrors": [
    3. "https://<your-mirror-address>"
    4. ]
    5. }

    Restart the Docker daemon for the change to take effect:

    1. sudo systemctl restart docker

    Practical tips:

    • Confirm image name and tags with docker search or the registry page before pulling
    • If a large pull fails, retry; layers already downloaded are not fetched again
    • On a private network, a private registry for vetted images speeds pulls and helps with version audit

    Container configuration and startup

    1. Basic docker run

    A typical Agent start command:

    1. docker run -d \
    2. --name my-agent \
    3. --restart unless-stopped \
    4. -p 8080:8080 \
    5. -v $(pwd)/data:/app/data \
    6. -v $(pwd)/config:/app/config \
    7. -e API_KEY=your_key_here \
    8. <image-name>:<version>

    Key flags:

    • --restart unless-stopped: restart the container after host reboot
    • -p: publish the service port to the host
    • -v: bind mounts for persistence (see below)
    • -e: environment variables for API keys, model settings, and similar config

    2. Docker Compose

    When the stack has more pieces (Agent, database, cache), describe it in Compose:

    1. services:
    2. agent:
    3. image: <image-name>:<version>
    4. ports:
    5. - "8080:8080"
    6. volumes:
    7. - ./data:/app/data
    8. - ./config:/app/config
    9. env_file:
    10. - .env
    11. restart: unless-stopped
    12. deploy:
    13. resources:
    14. limits:
    15. memory: 8G

    Compose keeps configuration as documentation, supports one-command start/stop (docker compose up -d), and makes service dependencies explicit—useful for teams and production.

    3. Persistence

    Containers are immutable; data written only in the container layer is lost when the container is removed. Mount to the host or a volume:

    • Runtime data such as session records and task state
    • Config files (change settings without rebuilding the image)
    • Log directories (central collection)

    On Windows with WSL 2, keep data on the Linux filesystem (paths inside the WSL distro) rather than /mnt/c or other Windows drive mounts for much better I/O.

    Security and secrets

    1. Do not put keys in the image or commit them to git. Use an env file (.env in .gitignore) or Docker secrets for API keys.
    2. Least privilege: run the process as a non-root user when possible; consider --read-only with only the mounts that must be writable.
    3. Network isolation: the default bridge network is enough for many cases; for multiple services, use a custom network and expose only required ports on the host.
    4. Resource limits: use --memory and --cpus so one container cannot starve the host.

    Verification and operations

    1. After deploy

    1. docker ps # confirm the container is running
    2. docker logs -f my-agent # follow logs
    3. curl http://localhost:8080/health # health check (use the service’s real endpoint)

    2. Day-to-day operations

    • Logs: configure log rotation (log-opts in daemon.json) so logs cannot fill the disk
    • Monitoring: use docker stats for CPU/memory; in production, plug into a unified monitoring and alerting stack
    • Upgrades: pull the new image → stop the old container → start a new one with the same mounts and the new image; persisted data is kept
    • Backup: regularly back up mounted data directories and config files

    Common issues

    Symptom Likely cause What to do
    Image pull times out Network or registry rate limits Configure a registry mirror, retry, or use a private registry
    Container keeps restarting Bad config, invalid key, unreachable dependency Check docker logs, env, and mounts
    Port conflict Host port already in use Map a different port or free the process
    Slow I/O on Windows Data on a Windows drive mount Move data onto the WSL filesystem
    No outbound network from the container DNS or proxy Check container networking and host proxy settings

    Summary

    Deploying an AI Agent with Docker on Windows and Linux boils down to four steps: prepare the environment → pull the image (with a mirror if needed) → start with persistence and config → verify and operate. Keep config and data outside the image, keep secrets off disk in the image, pin versions, and cap resources. That yields a cross-platform, maintainable setup you can upgrade smoothly. Teams that want more engineering rigor can add a private registry, an orchestrator, and unified monitoring, and fold the process into continuous delivery.