Servers
GPU Server Dedicated Server VPS Server
AI Hosting
GPT-OSS DeepSeek LLaMA Stable Diffusion Whisper
App Hosting
Odoo MySQL WordPress Node.js
Resources
Documentation FAQs Blog
Log In Sign Up
Servers

On Aws Ec2 Step-by-step: Ollama Docker Deployment

Learn how to deploy Ollama Docker on AWS EC2 Step-by-Step in this comprehensive guide. We cover everything from EC2 instance setup to running LLMs with persistent storage and web interfaces.

Marcus Chen
Cloud Infrastructure Engineer
14 min read

Deploying large language models has become easier than ever with Ollama, a containerized inference engine that simplifies LLM deployment. If you’re looking to run models like LLaMA 3.3, Mistral, or DeepSeek on AWS, Ollama Docker Deployment on AWS EC2 Step-by-Step provides a production-ready path forward. In this guide, I’ll walk you through the complete process based on hands-on experience deploying dozens of models across AWS infrastructure.

The beauty of Ollama Docker deployment on AWS EC2 is its simplicity combined with flexibility. Unlike complex Kubernetes setups, you can have a fully functional inference server running within 15-20 minutes. Whether you’re building a prototype or scaling to production, understanding this deployment method is essential for anyone serious about self-hosting AI models. This relates directly to Ollama Docker Deployment On Aws Ec2 Step-by-step.

Ollama Docker Deployment On Aws Ec2 Step-by-step – Prerequisites for Ollama Docker Deployment on AWS EC2

Before diving into Ollama Docker deployment on AWS EC2 Step-by-Step, ensure you have the foundational requirements in place. You’ll need an active AWS account with appropriate IAM permissions to launch EC2 instances. Additionally, familiarity with basic Linux commands and SSH will make the process smoother.

On the software side, you need SSH access capability from your local machine. Most importantly, understand that this deployment requires adequate storage and compute resources. I typically recommend having at least 50GB of storage for models and OS, though popular models like LLaMA 3.3 can require 20-40GB alone.

Ensure your AWS account has EC2 launch quotas available. Some regions have default limits on GPU instances, so verify this beforehand to avoid deployment delays. Having the AWS CLI installed locally isn’t strictly necessary, but it streamlines instance management significantly.

Ollama Docker Deployment On Aws Ec2 Step-by-step – Choosing the Right AWS Instance Types

The instance type you select fundamentally impacts your Ollama Docker deployment on AWS EC2 performance and costs. For CPU-only inference, t3.medium or t3.large instances work for small models. However, for serious inference work with larger models, GPU instances are essential. When considering Ollama Docker Deployment On Aws Ec2 Step-by-step, this becomes clear.

GPU Instance Options for Ollama Deployment

The g4dn.xlarge instance is my go-to recommendation for most Ollama deployments. It features an NVIDIA T4 GPU with 16GB VRAM, suitable for running 7B-13B parameter models efficiently. At approximately $390 monthly for on-demand pricing, it provides excellent value for inference workloads.

For larger models like 70B parameter variants, consider g4dn.2xlarge or g4dn.12xlarge instances. The g4dn.2xlarge doubles the T4 GPUs (dual T4s with 32GB total VRAM), accommodating larger quantized models. If you’re running cutting-edge models like DeepSeek-R1, these larger instances become more cost-effective due to reduced inference time.

For production deployments expecting heavy traffic, the newer g5 instances with NVIDIA A10G GPUs offer better throughput. The g5.2xlarge provides 24GB VRAM and superior multi-user concurrency compared to g4dn variants. I’ve tested both extensively, and g5 instances show 2-3x better throughput for concurrent requests.

Storage Considerations

Always select root volumes with at least 100GB of gp3 storage. Models download during runtime, and insufficient storage causes deployment failures. For multiple large models, 200GB+ is safer. Gp3 volumes offer better price-to-performance than gp2, making them my preferred choice for Ollama deployments.

Launching Your EC2 Instance

The process of launching an EC2 instance for Ollama Docker deployment on AWS EC2 Step-by-Step begins in the AWS Management Console. Navigate to EC2, select Launch Instance, and choose your desired AMI. I recommend Ubuntu 22.04 LTS for its stability and community support in the ML space.

Network and Security Configuration

Create a new security group specifically for your Ollama deployment. You’ll need to allow inbound traffic on port 11434 (Ollama default) and port 3000 (WebUI). Restrict SSH access to your IP address for security. Consider allowing HTTPS port 443 if you plan to use a reverse proxy in production.

Assign an Elastic IP address immediately after instance launch. This ensures your Ollama Docker deployment on AWS EC2 maintains consistent network connectivity. Document this IP address—you’ll need it throughout the deployment process.

IAM Role and Access

Attach an IAM role with EC2 instance profile permissions. This enables Systems Manager Session Manager access, providing a secure alternative to SSH without opening additional ports. It’s particularly valuable for security-conscious deployments and troubleshooting.

After instance launch, wait 2-3 minutes for initialization. Then SSH into your instance using your key pair. The first command should always be system update: sudo apt update && sudo apt upgrade -y. This ensures all security patches and dependencies are current before installing Docker.

Installing Docker for Ollama Deployment

Docker is fundamental to Ollama Docker deployment on AWS EC2 Step-by-Step. The containerization approach ensures consistent environments and simplified dependency management. Installation on Ubuntu is straightforward using the official Docker repository.

Docker Installation Steps

First, add Docker’s official GPG key and repository to your system. Execute these commands in sequence:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

After installation, enable Docker to start on system boot and add your user to the docker group. This eliminates the need for sudo with docker commands:

sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -a -G docker $USER
newgrp docker

NVIDIA Docker Runtime Configuration

For GPU-enabled instances, install the NVIDIA Docker runtime. This allows Docker containers to access GPU resources. The NVIDIA drivers must be installed first on the host system. Use this approach on Ubuntu: The importance of Ollama Docker Deployment On Aws Ec2 Step-by-step is evident here.

distribution=$(. /etc/os-release;echo $ID$VERSION_ID)

curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -

curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list

sudo apt update && sudo apt install -y nvidia-docker2

sudo systemctl restart docker

Verify GPU access within Docker by running: docker run --rm --gpus all nvidia/cuda:11.8.0-runtime-ubuntu22.04 nvidia-smi. This confirms your Ollama Docker deployment on AWS EC2 can access GPU resources properly. Understanding Ollama Docker Deployment On Aws Ec2 Step-by-step helps with this aspect.

Ollama Docker Deployment on AWS EC2 Step-by-Step

Now we reach the core of Ollama Docker deployment on AWS EC2 Step-by-Step—actually running the Ollama container. This is where your infrastructure truly comes alive with AI inference capabilities.

Launching the Ollama Container

Deploy the Ollama container with persistent storage using Docker’s volume mounting. This command creates a container that persists downloaded models across restarts:

docker run -d 
  --gpus all 
  -v ollama:/root/.ollama 
  -e OLLAMA_HOST=0.0.0.0:11434 
  -p 11434:11434 
  --name ollama 
  --restart always 
  ollama/ollama

The key parameters here: --gpus all enables GPU access, -v ollama:/root/.ollama creates persistent storage for models, -e OLLAMA_HOST=0.0.0.0:11434 makes Ollama accessible externally, and --restart always ensures your container survives system reboots. This comprehensive setup is essential for production Ollama deployments.

Accessing the Ollama Container

Once the container runs, enter it to download and test models. Execute: docker exec -it ollama /bin/bash. This opens an interactive shell inside your running Ollama container, allowing direct model management.

Pulling and Testing Models

Download your desired model using the ollama pull command. For testing, I recommend starting with llama2 or mistral, which are smaller than LLaMA 3.3: Ollama Docker Deployment On Aws Ec2 Step-by-step factors into this consideration.

ollama pull llama3.3

After the model downloads (this may take several minutes depending on size and internet speed), test it with: ollama run llama3.3. This starts an interactive chat session. Try a simple query like “Explain cloud computing in one sentence” to verify everything works.

The first run includes model loading time—don’t expect instant responses. Subsequent requests are faster once the model loads into GPU memory. Exit the interactive session by typing “exit” or pressing Ctrl+D.

Verifying Your Deployment

Test API access from outside the container by querying the Ollama endpoint. From your local machine: curl http://your-ec2-ip:11434/api/generate -d '{"model":"llama3.3","prompt":"Hello"}'. A successful response confirms your Ollama Docker deployment on AWS EC2 is functioning correctly.

Deploying Open WebUI for Easy Access

While API access is powerful, a web interface dramatically improves usability. Open WebUI provides a ChatGPT-like interface for your Ollama models, making them accessible to non-technical users.

WebUI Container Deployment

Deploy Open WebUI in another Docker container, linking it to your Ollama instance:

docker run -d 
  -p 3000:8080 
  -e OLLAMA_BASE_URL=http://host.docker.internal:11434 
  -v open-webui:/app/backend/data 
  --name open-webui 
  --restart always 
  ghcr.io/open-webui/open-webui:main

The critical parameter here is OLLAMA_BASE_URL=http://host.docker.internal:11434, which enables the WebUI container to communicate with your Ollama container. The volume mount -v open-webui:/app/backend/data persists chat history and user data.

Accessing Your Web Interface

Open your browser and navigate to http://your-ec2-ip:3000. On first access, you’ll see the Open WebUI login page. Create an initial admin account—this first user automatically becomes administrator. After this setup, your Ollama Docker deployment on AWS EC2 is accessible through an intuitive web interface.

The WebUI automatically detects available models from your Ollama instance. Users can switch between models, adjust parameters, and maintain conversation history without touching the command line. This accessibility makes Ollama deployments practical for teams, not just technical users.

Performance Optimization Techniques

Getting Ollama Docker deployment on AWS EC2 Step-by-Step running is half the battle. Optimizing performance ensures responsive inference and efficient resource utilization.

GPU Memory Management

Monitor GPU memory usage with: docker exec ollama nvidia-smi. Most 7B-13B models require 4-8GB VRAM comfortably. Larger models may need quantization to fit in available memory. Ollama automatically selects appropriate quantization levels, but you can override this in advanced configurations. This relates directly to Ollama Docker Deployment On Aws Ec2 Step-by-step.

If inference feels sluggish, check if your model is using CPU fallback instead of GPU. Slow responses often indicate the model loaded to system RAM rather than VRAM. Verify GPU acceleration is active in the nvidia-smi output.

CPU Thread Optimization

Ollama uses all available CPU threads by default. For shared systems, consider limiting threads to prevent CPU starvation. Set OLLAMA_NUM_THREAD environment variable in your docker run command: -e OLLAMA_NUM_THREAD=4 for a 4-core limitation.

Model Caching Strategy

Keep frequently-used models in memory by adjusting OLLAMA_KEEP_ALIVE. This parameter controls how long models stay loaded after the last request. Set it higher for continuous inference workloads, lower for intermittent usage to free GPU memory.

Test different settings: -e OLLAMA_KEEP_ALIVE=5m keeps models loaded for 5 minutes post-request. This balance prevents repeated model loading while freeing resources when idle.

Monitoring and Troubleshooting Your Setup

Maintaining a healthy Ollama Docker deployment on AWS EC2 requires ongoing monitoring and proactive troubleshooting. Common issues have straightforward solutions once you know what to look for. When considering Ollama Docker Deployment On Aws Ec2 Step-by-step, this becomes clear.

Container Health Monitoring

Check container status with: docker ps | grep ollama. This shows running containers. If your container isn’t listed, check logs with: docker logs ollama. Error messages here typically indicate configuration issues or resource constraints.

Monitor system resources using: docker stats ollama. This provides real-time CPU, memory, and network statistics. Watch for excessive CPU usage or approaching memory limits, which indicate your instance may be undersized.

Common Issues and Solutions

Model download failures: Verify internet connectivity and disk space. Models fail downloading if storage fills. Check available space with: df -h. Large models (70B+) require 50GB+ free space.

Slow inference: Confirm GPU acceleration is active with nvidia-smi. If GPU memory is full from another process, inference falls back to CPU. Check for competing containers using GPU resources.

WebUI connection issues: Ensure the OLLAMA_BASE_URL environment variable correctly points to your Ollama container. Network connectivity between containers depends on proper Docker networking configuration. The importance of Ollama Docker Deployment On Aws Ec2 Step-by-step is evident here.

Logging and Diagnostics

Enable verbose logging for deeper troubleshooting: docker exec ollama ollama list shows downloaded models. This confirms what’s actually available on your system. Compare against what the WebUI displays to identify sync issues.

Production Best Practices

Moving beyond development, production Ollama Docker deployment on AWS EC2 Step-by-Step requires additional considerations for reliability, security, and scalability.

Security Hardening

Never expose Ollama ports directly to the internet. Use a reverse proxy like Nginx in front of your Ollama API. This enables SSL/TLS encryption, authentication, and rate limiting. Additionally, restrict security group inbound rules to specific IP ranges rather than 0.0.0.0/0.

Implement API authentication using an API gateway. Tools like Kong or Tyk can sit between users and your Ollama instance, providing key-based access control and usage analytics.

Data Persistence and Backups

Docker volumes persist model data, but ensure you have backup strategy. For critical deployments, take EBS snapshots of your volume periodically. Automate this with AWS Backup or custom Lambda functions. Understanding Ollama Docker Deployment On Aws Ec2 Step-by-step helps with this aspect.

Scaling Considerations

Single EC2 instance deployments have capacity limits. For production with high traffic, consider multiple EC2 instances with load balancing. AWS Network Load Balancer can distribute requests across multiple Ollama instances, improving throughput and reliability.

Alternatively, migrate to ECS or EKS for orchestrated container management. These services automatically handle container health, scaling, and resource allocation—valuable for enterprise deployments.

Cost Optimization Strategies

Running Ollama Docker deployment on AWS EC2 can accumulate costs quickly. Strategic decisions minimize expenses without sacrificing performance significantly.

Instance Type Selection for Budget

Spot instances reduce g4dn instance costs by 70-80% compared to on-demand pricing. Spot instances are suitable for non-critical inference workloads tolerating occasional interruptions. Use Spot for development, testing, and non-production inference serving.

Savings Plans provide 20-30% discounts on on-demand pricing with 1-3 year commitments. For predictable workloads, these provide better economics than on-demand without Spot interruption risk. Ollama Docker Deployment On Aws Ec2 Step-by-step factors into this consideration.

Right-Sizing Your Instance

Start with g4dn.xlarge, the smallest viable GPU instance. If performance proves adequate, avoid upgrading to larger variants. Many use cases run perfectly on single T4 GPUs. I’ve seen teams unnecessarily pay for g4dn.12xlarge when g4dn.xlarge would suffice.

Monitor actual utilization. If your GPU runs at 30% capacity, you’re probably over-provisioned. Scale down gradually—performance needs often surprise you.

Network and Data Transfer Costs

Data transfer costs add up quickly with high-volume inference. Use EC2 instances in the same region as your application users. Cross-region data transfer costs $0.02 per GB, becoming significant at scale.

For extremely cost-sensitive deployments, evaluate cheaper regions. Some AWS regions cost 40-50% less than US East. If latency isn’t critical, deploying to cheaper regions significantly reduces overall costs.

Key Takeaways for Success

Successful Ollama Docker deployment on AWS EC2 Step-by-Step follows a logical progression: planning instance selection, configuring Docker and GPU support, deploying containers, and optimizing performance. Each step builds on previous configurations.

The most common mistakes occur in initial planning—choosing undersized instances or insufficient storage. Take time with prerequisites; they prevent costly troubleshooting later. Start conservative; you can always upgrade, but downgrading creates operational friction.

Document your specific configuration. Record environment variables, volume mount points, and security group rules. This documentation becomes invaluable when scaling to multiple instances or migrating to other platforms. Version control your Docker commands and environment files for reproducibility.

Test everything in development before production deployment. The same Ollama Docker deployment on AWS EC2 that works perfectly in testing may fail under production load. Establish monitoring and alerting immediately—reactive troubleshooting in production is stressful and expensive. Understanding Ollama Docker Deployment On Aws Ec2 Step-by-step is key to success in this area.

Share this article:
Marcus Chen
Written by

Marcus Chen

Senior Cloud Infrastructure Engineer & AI Systems Architect

10+ years of experience in GPU computing, AI deployment, and enterprise hosting. Former NVIDIA and AWS engineer. Stanford M.S. in Computer Science. I specialize in helping businesses deploy AI models like DeepSeek, LLaMA, and Stable Diffusion on optimized infrastructure.