Deploying a Docker App on Oracle Cloud Free Tier (1GB VM)

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)

  1. Go to Oracle Cloud Console
  2. Click Create Instance
  3. 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:


๐Ÿ“ฆ 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=1g is 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-cache when 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!

Leave a Comment