This commit adds comprehensive Docker support for running Swarms on x86_64 (amd64) architecture. Changes: - Updated Dockerfile with explicit platform specification (--platform=linux/amd64) - Created root-level Dockerfile for easier access - Created root-level docker-compose.yml with amd64 platform settings - Updated scripts/docker/Dockerfile and docker-compose.yml for amd64 - Added DOCKER.md with comprehensive documentation - Created build-docker-amd64.sh script for easy image building - Created run-docker-amd64.sh script for quick container startup Key Features: - Multi-stage build for optimized image size - Explicit x86_64/amd64 platform targeting - Health checks for container monitoring - Non-root user for security - Development and production configurations - Comprehensive documentation and examples The Docker setup uses Python 3.11-slim-bullseye base image and includes UV package manager for faster dependency installation.pull/1174/head
parent
1bb4dab6a1
commit
63954e6f41
@ -0,0 +1,225 @@
|
||||
# Docker Setup for Swarms (x86_64/amd64)
|
||||
|
||||
This repository includes Docker support for running Swarms on x86_64 (amd64) architecture.
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Option 1: Using Docker Compose (Recommended)
|
||||
|
||||
```bash
|
||||
# Build and run the container
|
||||
docker-compose up -d
|
||||
|
||||
# View logs
|
||||
docker-compose logs -f swarms
|
||||
|
||||
# Stop the container
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
### Option 2: Using Docker Build
|
||||
|
||||
```bash
|
||||
# Build the image
|
||||
docker build --platform linux/amd64 -t swarms:latest .
|
||||
|
||||
# Run the container
|
||||
docker run --platform linux/amd64 -it swarms:latest bash
|
||||
|
||||
# Run with environment variables
|
||||
docker run --platform linux/amd64 \
|
||||
-e OPENAI_API_KEY=your_key_here \
|
||||
-e ANTHROPIC_API_KEY=your_key_here \
|
||||
-v $(pwd):/app \
|
||||
swarms:latest
|
||||
```
|
||||
|
||||
### Option 3: Pull from Docker Hub
|
||||
|
||||
```bash
|
||||
# Pull the pre-built image
|
||||
docker pull swarmscorp/swarms:latest
|
||||
|
||||
# Note: The pre-built image may need to be updated for amd64 compatibility
|
||||
# Use the local build method above for guaranteed amd64 support
|
||||
```
|
||||
|
||||
## Available Services
|
||||
|
||||
The `docker-compose.yml` includes two services:
|
||||
|
||||
### 1. swarms (Default Service)
|
||||
- Runs a basic swarms container
|
||||
- Includes health checks
|
||||
- Auto-restarts unless stopped
|
||||
|
||||
### 2. swarms-dev (Development Service)
|
||||
- Interactive bash shell
|
||||
- Ideal for development and testing
|
||||
- Mounted volumes for live code changes
|
||||
|
||||
```bash
|
||||
# Run development container
|
||||
docker-compose up -d swarms-dev
|
||||
|
||||
# Attach to the container
|
||||
docker exec -it swarms-dev-container bash
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
This Docker image is explicitly built for **x86_64 (amd64)** architecture using:
|
||||
- Base image: `python:3.11-slim-bullseye`
|
||||
- Platform: `linux/amd64`
|
||||
- Multi-stage build for optimized image size
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Configure your Swarms instance by setting environment variables:
|
||||
|
||||
```bash
|
||||
# Create a .env file in the root directory
|
||||
cat > .env << EOF
|
||||
OPENAI_API_KEY=sk-...
|
||||
ANTHROPIC_API_KEY=sk-ant-...
|
||||
GOOGLE_API_KEY=...
|
||||
EOF
|
||||
```
|
||||
|
||||
Then use with docker-compose:
|
||||
|
||||
```bash
|
||||
docker-compose --env-file .env up -d
|
||||
```
|
||||
|
||||
## Volume Mounts
|
||||
|
||||
The docker-compose configuration mounts the following directories:
|
||||
|
||||
- `.:/app` - Main application code
|
||||
- `./data:/app/data` - Data directory
|
||||
- `./models:/app/models` - Model files
|
||||
|
||||
## Building for Different Architectures
|
||||
|
||||
While this Dockerfile is optimized for amd64, you can build for other architectures:
|
||||
|
||||
```bash
|
||||
# Build for multiple architectures (requires buildx)
|
||||
docker buildx create --use
|
||||
docker buildx build --platform linux/amd64,linux/arm64 -t swarms:multiarch .
|
||||
```
|
||||
|
||||
## Health Checks
|
||||
|
||||
The container includes a built-in health check that verifies the swarms package can be imported:
|
||||
|
||||
```bash
|
||||
# Check container health
|
||||
docker inspect --format='{{.State.Health.Status}}' swarms-container
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Issue: Architecture mismatch
|
||||
If you're getting architecture-related errors, ensure Docker is configured for amd64:
|
||||
|
||||
```bash
|
||||
# Check current architecture
|
||||
docker info | grep Architecture
|
||||
|
||||
# Force amd64 platform
|
||||
docker run --platform linux/amd64 swarms:latest
|
||||
```
|
||||
|
||||
### Issue: Build fails
|
||||
If the build fails, try cleaning Docker cache:
|
||||
|
||||
```bash
|
||||
docker system prune -a
|
||||
docker-compose build --no-cache
|
||||
```
|
||||
|
||||
### Issue: Import errors
|
||||
If you encounter import errors, rebuild the image:
|
||||
|
||||
```bash
|
||||
docker-compose down
|
||||
docker-compose build --no-cache
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
### Running Custom Scripts
|
||||
|
||||
```bash
|
||||
# Run a Python script
|
||||
docker run --platform linux/amd64 -v $(pwd):/app swarms:latest python your_script.py
|
||||
|
||||
# Using docker-compose
|
||||
docker-compose run swarms python your_script.py
|
||||
```
|
||||
|
||||
### Interactive Python Shell
|
||||
|
||||
```bash
|
||||
# Start Python REPL
|
||||
docker run --platform linux/amd64 -it swarms:latest python
|
||||
|
||||
# Or with docker-compose
|
||||
docker-compose run swarms python
|
||||
```
|
||||
|
||||
### Installing Additional Dependencies
|
||||
|
||||
Create a custom Dockerfile extending the base image:
|
||||
|
||||
```dockerfile
|
||||
FROM swarms:latest
|
||||
|
||||
USER root
|
||||
RUN pip install additional-package
|
||||
USER swarms
|
||||
```
|
||||
|
||||
## Production Deployment
|
||||
|
||||
For production deployments:
|
||||
|
||||
1. Use specific version tags instead of `latest`
|
||||
2. Configure proper logging and monitoring
|
||||
3. Set resource limits in docker-compose.yml
|
||||
4. Use secrets management for API keys
|
||||
5. Enable automatic container restarts
|
||||
|
||||
Example production configuration:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
swarms:
|
||||
image: swarms:1.0.0
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '2.0'
|
||||
memory: 4G
|
||||
reservations:
|
||||
cpus: '1.0'
|
||||
memory: 2G
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
For issues or questions:
|
||||
- GitHub Issues: https://github.com/kyegomez/swarms/issues
|
||||
- Documentation: https://docs.swarms.world
|
||||
|
||||
## License
|
||||
|
||||
MIT License - See LICENSE file for details
|
||||
@ -0,0 +1,49 @@
|
||||
# Multi-stage build for optimized Docker image
|
||||
# Explicitly target x86_64 (amd64) architecture
|
||||
FROM --platform=linux/amd64 python:3.11-slim-bullseye as builder
|
||||
|
||||
# Install system dependencies for building
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential gcc curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install UV for faster package management
|
||||
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||
|
||||
# Create a virtual environment and install dependencies
|
||||
RUN uv venv /opt/venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
# Install the swarms package using UV
|
||||
RUN uv pip install --system -U swarms
|
||||
|
||||
# Final stage
|
||||
FROM --platform=linux/amd64 python:3.11-slim-bullseye
|
||||
|
||||
# Environment config for speed and safety
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PATH="/opt/venv/bin:${PATH}" \
|
||||
PYTHONPATH="/app:${PYTHONPATH}" \
|
||||
USER=swarms
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy virtual environment from builder stage
|
||||
COPY --from=builder /opt/venv /opt/venv
|
||||
|
||||
# Add non-root user
|
||||
RUN useradd -m -s /bin/bash -U $USER && \
|
||||
chown -R $USER:$USER /app
|
||||
|
||||
# Copy application code
|
||||
COPY --chown=$USER:$USER . .
|
||||
|
||||
# Switch to non-root
|
||||
USER $USER
|
||||
|
||||
# Optional health check
|
||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
||||
CMD python -c "import swarms; print('Health check passed')" || exit 1
|
||||
@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Build script for Swarms Docker image (x86_64/amd64)
|
||||
# This script builds the Swarms Docker image specifically for amd64 architecture
|
||||
|
||||
set -e
|
||||
|
||||
echo "=========================================="
|
||||
echo "Building Swarms Docker Image for amd64"
|
||||
echo "=========================================="
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Check if Docker is installed
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "Error: Docker is not installed. Please install Docker first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check current architecture
|
||||
ARCH=$(uname -m)
|
||||
echo -e "${BLUE}Current system architecture: $ARCH${NC}"
|
||||
|
||||
# Build image
|
||||
echo -e "${BLUE}Building Docker image for linux/amd64...${NC}"
|
||||
docker build --platform linux/amd64 -t swarms:amd64 -t swarms:latest .
|
||||
|
||||
# Verify the build
|
||||
echo -e "${BLUE}Verifying the build...${NC}"
|
||||
docker images swarms
|
||||
|
||||
echo -e "${GREEN}=========================================="
|
||||
echo "Build completed successfully!"
|
||||
echo "==========================================${NC}"
|
||||
echo ""
|
||||
echo "To run the container:"
|
||||
echo " docker run --platform linux/amd64 -it swarms:latest bash"
|
||||
echo ""
|
||||
echo "Or use docker-compose:"
|
||||
echo " docker-compose up -d"
|
||||
echo ""
|
||||
echo "For more information, see DOCKER.md"
|
||||
@ -0,0 +1,58 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
swarms:
|
||||
platform: linux/amd64
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
platforms:
|
||||
- linux/amd64
|
||||
image: swarms:latest
|
||||
container_name: swarms-container
|
||||
environment:
|
||||
- PYTHONUNBUFFERED=1
|
||||
- PYTHONPATH=/app
|
||||
# Add your API keys here or use .env file
|
||||
# - OPENAI_API_KEY=${OPENAI_API_KEY}
|
||||
# - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
|
||||
# - GOOGLE_API_KEY=${GOOGLE_API_KEY}
|
||||
volumes:
|
||||
- .:/app
|
||||
- ./data:/app/data
|
||||
- ./models:/app/models
|
||||
working_dir: /app
|
||||
command: python -c "import swarms; print('Swarms container is running successfully!')"
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import swarms; print('Health check passed')"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
swarms-dev:
|
||||
platform: linux/amd64
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
platforms:
|
||||
- linux/amd64
|
||||
image: swarms:dev
|
||||
container_name: swarms-dev-container
|
||||
environment:
|
||||
- PYTHONUNBUFFERED=1
|
||||
- PYTHONPATH=/app
|
||||
volumes:
|
||||
- .:/app
|
||||
- ./data:/app/data
|
||||
- ./models:/app/models
|
||||
working_dir: /app
|
||||
command: bash
|
||||
stdin_open: true
|
||||
tty: true
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
default:
|
||||
name: swarms-network
|
||||
@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Quick start script for Swarms Docker container (x86_64/amd64)
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo "=========================================="
|
||||
echo "Swarms Docker Quick Start (amd64)"
|
||||
echo "=========================================="
|
||||
|
||||
# Check if Docker is installed
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "Error: Docker is not installed. Please install Docker first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if image exists
|
||||
if ! docker image inspect swarms:latest &> /dev/null; then
|
||||
echo -e "${YELLOW}Swarms image not found. Building image...${NC}"
|
||||
./build-docker-amd64.sh
|
||||
fi
|
||||
|
||||
echo -e "${BLUE}Starting Swarms container...${NC}"
|
||||
|
||||
# Check if using docker-compose or docker run
|
||||
if [ "$1" == "compose" ]; then
|
||||
echo -e "${BLUE}Using docker-compose...${NC}"
|
||||
docker-compose up -d
|
||||
echo -e "${GREEN}Container started! View logs with: docker-compose logs -f${NC}"
|
||||
else
|
||||
echo -e "${BLUE}Using docker run...${NC}"
|
||||
docker run --platform linux/amd64 \
|
||||
--name swarms-container \
|
||||
-v $(pwd):/app \
|
||||
-e PYTHONUNBUFFERED=1 \
|
||||
-it \
|
||||
--rm \
|
||||
swarms:latest bash
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}=========================================="
|
||||
echo "Swarms is ready!"
|
||||
echo "==========================================${NC}"
|
||||
Loading…
Reference in new issue