Local Deployment with SFAI SDK¶
This notebook demonstrates how to deploy applications locally using Docker containers with the SFAI SDK. Local deployment is perfect for development, testing, and quick prototyping.
Overview¶
Local deployment uses Docker to containerize and run your application on your local machine. The platform automatically:
- Builds a Docker image from your application
- Finds an available port (starting from 8080)
- Provides easy access to logs, status, and management commands
Prerequisites¶
- Docker installed and running on your system
- SFAI SDK installed (
pip install sfai
) - A Dockerfile in your application directory
!sfai app init
Step 2: Deploy to Local¶
This builds the Docker image and runs the container.
!sfai app deploy
Step 3: Open in Browser¶
This opens your application in the default browser.
!sfai app open
Step 4: View Logs¶
Check the container logs to see what's happening.
!sfai app logs
Step 5: Check Status¶
Verify if your container is running.
!sfai app status
Step 6: View App Context¶
!sfai app context
Step 7: Clean Up¶
Stop and remove the container when you're done.
# Clean up when done (uncomment to run)
!sfai app delete
from sfai.app import init, get_context
from sfai.app.deploy import deploy
from sfai.app.status import status
from sfai.app.open import open
from sfai.app.logs import logs
from sfai.app.delete import delete
Step 1: Initialize App¶
Initialize your app with a template (creates local platform by default).
init(template="fastapi_hello")
Step 2: Deploy to Local¶
Deploy your application to the local Docker environment.
deploy()
Step 3: Get Context and URL¶
Get the deployment context to see where your app is running.
get_context()
Step 4: Open in Browser¶
Open your application in the default browser.
open(path="/invocations")
Step 5: View Logs¶
Check the container logs.
logs()
Optional: Check Status¶
Check if your container is running.
status()
Optional: Clean Up¶
Stop and remove the container when you're done.
delete()
!docker ps
Debug Container Issues¶
# Check logs if container won't start
!sfai app logs
# Check status
!sfai app status
Check App Context¶
# Check port and URL
!sfai app context
# Try opening again
!sfai app open
Next Steps¶
After successful local deployment, you can:
- Deploy to cloud platforms (Heroku, AWS EKS, GCP)
- Set up CI/CD pipelines
- Configure monitoring and logging
For detailed CLI command options, see CLI Commands Documentation. For cloud deployment guides, see other use case documentation.