Table of Contents
A Complete Step-by-Step Guide (FastAPI + Docker + Selenium)
If you’re building side projects, automation tools, or learning cloud deployment, Oracle Cloud’s free tier VM is one of the best places to start.
In this guide, I’ll walk you through how I deployed a Dockerized FastAPI + Selenium app on a 1GB RAM VM, optimized it to avoid crashes, and made it production-ready.
๐ Why This Guide Matters
A 1GB VM is very limited. Without proper setup, you may face:
- App crashes
- Docker failures
- Selenium memory errors
- Unresponsive server
This guide includes all fixes we learned the hard way ๐
๐งฑ Step 1 โ Create VM (Oracle Cloud)
- Go to Oracle Cloud Console
- Click Create Instance
- Use the following configuration:
- Shape:
VM.Standard.E2.1.Micro - CPU:
1 OCPU - Memory:
1 GB - Boot Volume:
100 GB - OS: Ubuntu 22.04
๐ Add your SSH public key during creation
๐ Step 2 โ SSH into VM
chmod 600 your-key.pem
ssh -i your-key.key ubuntu@<PUBLIC_IP>
๐ Step 3 โ Update System
sudo apt update && sudo apt upgrade -y
If you see a kernel update message:
sudo reboot
Reconnect after reboot.
๐พ Step 4 โ Create Swap (VERY IMPORTANT)
A 1GB VM is not enough for Docker + Selenium.
Create a 2GB swap file:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Make it permanent:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Verify:
free -h
๐ This prevents your app from crashing due to low memory.
๐ณ Step 5 โ Install Docker
sudo apt install -y docker.io
Enable Docker:
sudo systemctl start docker
sudo systemctl enable docker
Allow non-root usage:
sudo usermod -aG docker $USER
Reconnect:
exit
ssh -i your-key.pem ubuntu@<PUBLIC_IP>
Verify:
docker --version
๐ Step 6 โ Open Required Ports
Oracle Cloud Security List
Add ingress rule:
- Source:
0.0.0.0/0 - Protocol: TCP
- Port:
8001
Ubuntu Firewall
sudo ufw allow 8001
sudo ufw enable
๐ Step 7 โ Setup GitHub SSH
Generate key:
ssh-keygen -t ed25519 -C "your-email"
Start agent:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Copy public key:
cat ~/.ssh/id_ed25519.pub
Add it to GitHub โ Settings โ SSH Keys
Test connection:
ssh -T [email protected]
๐ฆ Step 8 โ Clone Repository
git clone [email protected]:<your-username>/<repo>.git
cd <repo>
๐๏ธ Step 9 โ Build Docker Image
docker build -t epay-auto:1.0 .
โถ๏ธ Step 10 โ Run Container
docker run -d \
--name epay-auto \
-p 8001:8001 \
--shm-size=1g \
epay-auto:1.0
๐ --shm-size=1g is critical for Selenium stability
๐ Step 11 โ Access Your App
http://<PUBLIC_IP>:8001
โ ๏ธ Note: This is HTTP, not HTTPS
๐ Step 12 โ Check Logs
docker logs -f epay-auto
๐ Step 13 โ Update Deployment
After making code changes:
cd <repo>
git pull
Stop old container:
docker stop epay-auto
docker rm epay-auto
(Optional) remove old image:
docker rmi epay-auto:1.0
Rebuild:
docker build --no-cache -t epay-auto:1.1 .
Run again:
docker run -d \
--name epay-auto \
-p 8001:8001 \
--shm-size=1g \
epay-auto:1.1
๐ Step 14 โ Versioning & Rollback
Using version tags helps you roll back if something breaks.
Rollback Example
docker stop epay-auto
docker rm epay-auto
# Run previous version
docker run -d \
--name epay-auto \
-p 8001:8001 \
--shm-size=1g \
epay-auto:1.0
๐งน Step 15 โ Cleanup Disk Space
Check usage:
docker system df
Remove unused data:
docker system prune -a
โก Troubleshooting
App not accessible
docker ps
sudo ss -tulnp | grep 8001
Check:
- OCI security rules
- Firewall (ufw)
App crashes
Ensure:
- Swap is enabled
--shm-size=1gis set
Old code still showing
docker build --no-cache -t epay-auto:1.1 .
GitHub SSH issue
If you see:
Permission denied (publickey)
Make sure:
- SSH key is added to GitHub
- SSH agent is running
๐ง Key Learnings
- Always add swap for low-memory VMs
- Selenium requires shared memory (
--shm-size) - OCI security rules are mandatory
- Use Docker tags for safe deployments
- Always rebuild with
--no-cachewhen debugging
๐ฏ Final Architecture
User โ Public IP โ OCI Firewall โ VM โ Docker โ FastAPI
โ Selenium
๐ Conclusion
With proper setup, even a free 1GB VM can run a production-ready Docker app smoothly.
This setup is perfect for:
- Side projects
- Automation tools
- Learning DevOps
- Portfolio projects
โจ Next Improvements
- Add HTTPS (Nginx + SSL)
- Use Docker Compose
- Add CI/CD pipeline
- Use domain instead of IP
If this helped you, feel free to share or connect!