# Docker Caching Research and Tests

This directory contains research and testing code for Docker image caching strategies in Flow SDK.

## Overview

These files explore different approaches to Docker image caching and persistence, leading to the fix implemented in the main codebase.

## Files

### Research Scripts
- `test_docker_image_preloading.py` - Tests various Docker image preloading methods
- `test_docker_persistent_storage.py` - Explores persistent storage options for Docker
- `test_docker_persistent_mount.py` - Verifies mounting volumes to /var/lib/docker

### Implementation Reference
- `correct_docker_cache_implementation.sh` - Shows the correct way to implement Docker caching
- `setup_docker_persistent_cache.py` - Script to set up persistent Docker cache on instances

## Key Findings

1. **Simple Fix**: Check if image exists before pulling
   ```bash
   docker image inspect $IMAGE >/dev/null 2>&1 || docker pull $IMAGE
   ```

2. **Persistent Storage**: Mount volume to `/var/lib/docker` for cache persistence
   ```python
   volumes=[VolumeSpec(size_gb=100, mount_path="/var/lib/docker")]
   ```

3. **Local Registry**: Can set up local registry for fast pulls
   ```bash
   docker run -d -p 5000:5000 --name registry \
     -v /mnt/local/registry:/var/lib/registry registry:2
   ```

## What Was Implemented

Based on this research, a one-line fix was implemented in `src/flow/providers/fcp/script_sections.py`:
- Changed from always pulling to checking if image exists first
- Works with both ephemeral and persistent storage
- No complex abstractions needed

## Running These Tests

These are primarily research/exploration scripts. To run:

```bash
# Test Docker mounting behavior
python test_docker_persistent_mount.py <instance_ip> <ssh_key>

# Explore caching strategies
python test_docker_image_preloading.py <instance_ip> <ssh_key>
```