This Dockerfile provides a complete, production-ready environment for TeraSim based on Ubuntu 22.04 and Python 3.10. It includes all necessary dependencies and tools for running autonomous vehicle simulations.
- ✅ Compilers: gcc, g++, build-essential
- ✅ SUMO 1.23.1: Traffic simulation engine (installed via pip)
- ✅ SUMO Tools: Full toolchain cloned to
~/.terasim/deps/sumo - ✅ Redis: Required for service components
- ✅ Python Dependencies: All packages including Cython extensions
- ✅ Optimized Build: Multi-stage Docker build (~2-3 GB final image)
# Build and start the container
docker-compose up -d --build
# Enter the container
docker-compose exec terasim bash
# Run simulation inside container
python run_experiments.py
# Stop the container
docker-compose down# Build the image
docker build -t terasim:latest .
# Run container in interactive mode
docker run -it --name terasim \
-p 8000:8000 \
-p 6379:6379 \
-v $(pwd)/outputs:/app/TeraSim/outputs \
-v $(pwd)/logs:/app/TeraSim/logs \
terasim:latest
# Inside the container, start Redis (if needed)
redis-server --daemonize yes
# Run your simulation
python run_experiments.py# Standard simulation (police pullover scenario)
docker-compose exec terasim python run_experiments.py
# Debug mode (cutin scenario, GUI required)
docker-compose exec terasim python run_experiments_debug.py
# Start FastAPI service
docker-compose exec terasim python run_service.py
# Run example scripts
docker-compose exec terasim python examples/scripts/example.py# Run all tests
docker-compose exec terasim pytest
# Run specific test suite
docker-compose exec terasim pytest tests/test_core/
# Generate HTML coverage report
docker-compose exec terasim pytest --cov=terasim --cov-report=html
# Run only fast tests (skip slow integration tests)
docker-compose exec terasim pytest -m "not slow"# Format code with Black
docker-compose exec terasim black packages/
# Lint with Ruff
docker-compose exec terasim ruff check packages/
# Type checking with mypy
docker-compose exec terasim mypy packages/terasim/
# Sort imports with isort
docker-compose exec terasim isort packages/The Docker Compose configuration automatically mounts volumes for data persistence:
./outputs→ Simulation output files./logs→ Log files
Your data persists on the host machine even after container removal.
- 8000: TeraSim FastAPI service endpoint
- 6379: Redis database
The following environment variables are pre-configured in the container:
SUMO_HOME=/root/.terasim/deps/sumo
PATH=$SUMO_HOME/bin:$PATH
PYTHONUNBUFFERED=1Default resource limits in docker-compose.yml:
deploy:
resources:
limits:
cpus: '4'
memory: 8G
reservations:
cpus: '2'
memory: 4GAdjust these values based on your simulation requirements.
Edit the command field in docker-compose.yml:
# Auto-start simulation on container launch
command: sh -c "redis-server --daemonize yes && python run_experiments.py"
# Auto-start FastAPI service
command: sh -c "redis-server --daemonize yes && python run_service.py"
# Keep container running with bash (default)
command: sh -c "redis-server --daemonize yes && /bin/bash"Uncomment the Redis service in docker-compose.yml:
services:
redis:
image: redis:7-alpine
container_name: terasim-redis
ports:
- "6379:6379"
volumes:
- redis-data:/data
command: redis-server --appendonly yes
volumes:
redis-data:Then update the TeraSim service to link to Redis:
services:
terasim:
# ... other config ...
depends_on:
- redis
environment:
- REDIS_HOST=redis# Clean Docker cache and rebuild
docker-compose build --no-cache
# Check Docker disk space
docker system df
# Prune unused resources
docker system prune -a# Check Redis status inside container
docker-compose exec terasim redis-cli ping
# Manually start Redis
docker-compose exec terasim redis-server --daemonize yes
# View Redis logs
docker-compose exec terasim redis-cli INFO# Verify environment variable
docker-compose exec terasim echo $SUMO_HOME
# Manually set if needed
docker-compose exec terasim bash -c "export SUMO_HOME=/root/.terasim/deps/sumo"
# Check SUMO installation
docker-compose exec terasim sumo --version# On host machine, adjust permissions
chmod -R 777 outputs logs
# Or change ownership to your user
sudo chown -R $USER:$USER outputs logs# View container logs
docker-compose logs terasim
# Check specific error messages
docker-compose logs --tail=50 terasim
# Restart container
docker-compose restart terasim# Verify package installation inside container
docker-compose exec terasim python -c "import terasim; print(terasim.__version__)"
# Reinstall packages if needed
docker-compose exec terasim pip install -e packages/terasim- Edit code on your host machine
- Rebuild the container to apply changes:
docker-compose up -d --buildAlternatively, mount your source code as a volume for live editing:
services:
terasim:
volumes:
- ./packages:/app/TeraSim/packages# Enter container with bash
docker-compose exec terasim bash
# Run Python interactively
docker-compose exec terasim python
# Use IPython for better debugging
docker-compose exec terasim pip install ipython
docker-compose exec terasim ipythonFor SUMO GUI (sumo-gui) to work, you need X11 forwarding:
services:
terasim:
environment:
- DISPLAY=$DISPLAY
volumes:
- /tmp/.X11-unix:/tmp/.X11-unixOn the host:
# Allow X11 connections
xhost +local:docker
# Run container
docker-compose up -d- Base Image:
ubuntu:22.04 - Python Version:
3.10 - SUMO Version:
1.23.1 - Build Type: Multi-stage (optimized)
- Estimated Size: 2-3 GB
- Note: Base image excludes
terasim-cosmos(requires GPU support)
For full TeraSim-Cosmos functionality with GPU support, use the dedicated GPU Dockerfile:
# Navigate to terasim-cosmos package
cd packages/terasim-cosmos
# Build and run GPU-enabled image
docker-compose -f docker-compose.gpu.yml up -d --build
# Enter container
docker-compose -f docker-compose.gpu.yml exec terasim-cosmos bashSee packages/terasim-cosmos/README_DOCKER_GPU.md for detailed GPU setup instructions.
-
Use BuildKit: Enable faster builds with Docker BuildKit:
DOCKER_BUILDKIT=1 docker-compose build
-
Layer Caching: Order Dockerfile commands from least to most frequently changed
-
Parallel Builds: Build with multiple CPU cores:
docker-compose build --parallel
-
Resource Allocation: Increase Docker Desktop resources in Settings → Resources
For issues, questions, or contributions:
- GitHub Issues: https://github.com/mcity/TeraSim/issues
- Discussions: https://github.com/mcity/TeraSim/discussions
- Documentation: See main README.md and CLAUDE.md
- TeraSim Core: Apache 2.0 License
- TeraSim Visualization Tools: MIT License
See LICENSE for details.