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
dockergroup so you do not need elevated privileges for every command:
sudo usermod -aG docker $USERnewgrp 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:
docker versiondocker 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:
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:
{"registry-mirrors": ["https://<your-mirror-address>"]}
Restart the Docker daemon for the change to take effect:
sudo systemctl restart docker
Practical tips:
- Confirm image name and tags with
docker searchor 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:
docker run -d \--name my-agent \--restart unless-stopped \-p 8080:8080 \-v $(pwd)/data:/app/data \-v $(pwd)/config:/app/config \-e API_KEY=your_key_here \<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:
services:agent:image: <image-name>:<version>ports:- "8080:8080"volumes:- ./data:/app/data- ./config:/app/configenv_file:- .envrestart: unless-stoppeddeploy:resources:limits: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
- Do not put keys in the image or commit them to git. Use an env file (
.envin.gitignore) or Docker secrets for API keys. - Least privilege: run the process as a non-root user when possible; consider
--read-onlywith only the mounts that must be writable. - 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.
- Resource limits: use
--memoryand--cpusso one container cannot starve the host.
Verification and operations
1. After deploy
docker ps # confirm the container is runningdocker logs -f my-agent # follow logscurl http://localhost:8080/health # health check (use the service’s real endpoint)
2. Day-to-day operations
- Logs: configure log rotation (
log-optsindaemon.json) so logs cannot fill the disk - Monitoring: use
docker statsfor 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.
