Skip to main content
Blog
Home

/

posts

/

Oracle Always Free: 'Out of Host Capacity'

Oracle Always Free: 'Out of Host Capacity'

This is a straight-to-the-point tutorial for creating an Oracle Cloud Always Free A1 Flex instance when the web console keeps failing with:

Out of host capacity for shape VM.Standard.A1.Flex

We will use Oracle Cloud Shell + OCI CLI to retry instance creation across all Availability Domains.


Goal

Create this instance:

Shape: VM.Standard.A1.Flex
OCPUs: 4
RAM: 24 GB
Boot volume: 100 GB
Boot performance: 20 VPU
OS: Ubuntu 22.04 ARM64
Network: Public subnet with public IPv4

Note: 4 OCPU + 24 GB RAM is the full Always Free A1 allowance. If you already have another A1 instance, adjust the numbers.


0. Before you start

You should already have:

Oracle Cloud account
A VCN with internet connectivity
A public subnet
An SSH public key

If you do not have a VCN/public subnet yet, create it first:

Oracle Console → Networking → Virtual Cloud Networks
→ Start VCN Wizard
→ Create VCN with Internet Connectivity

Use something like:

VCN name: my-vcn
Public subnet: public-subnet-my-vcn
Private subnet: leave default

For this tutorial, the instance must use the public subnet, not the private one.


1. Open Oracle Cloud Shell

In Oracle Console, click the terminal icon in the top-right:

>_

Then check that OCI CLI works:

oci --version

You should see something like:

3.xx.x

2. Get your Availability Domains

Run:

oci iam availability-domain list --all --output table

You should see something like:

cCby:EU-FRANKFURT-1-AD-1
cCby:EU-FRANKFURT-1-AD-2
cCby:EU-FRANKFURT-1-AD-3

Save those names. We will put them in the script later.


3. Set your compartment ID

If you are creating the instance in the root compartment, your compartment ID is usually your tenancy OCID.

From the previous command output, copy the compartment-id, then set:

COMPARTMENT_ID="ocid1.tenancy.oc1..YOUR_TENANCY_OCID_HERE"

Check it:

echo "$COMPARTMENT_ID"

4. Get your VCN OCID

Replace my-vcn if your VCN has a different name:

oci network vcn list --all \
  --compartment-id "$COMPARTMENT_ID" \
  --query "data[?\"display-name\"=='my-vcn'].{name:\"display-name\",id:id}" \
  --output table

If you get no result, check your VCN name in the Oracle Console.

When you get the VCN OCID, set it:

VCN_ID="ocid1.vcn.oc1.REGION.YOUR_VCN_OCID_HERE"

5. Get your public subnet OCID

Run:

oci network subnet list --all \
  --compartment-id "$COMPARTMENT_ID" \
  --vcn-id "$VCN_ID" \
  --query "data[].{name:\"display-name\",id:id,cidr:\"cidr-block\"}" \
  --output table

You should see something like:

private-subnet-my-vcn  10.0.1.0/24
public-subnet-my-vcn   10.0.0.0/24

Copy the OCID for the public subnet, not the private subnet.

Set it:

SUBNET_ID="ocid1.subnet.oc1.REGION.YOUR_PUBLIC_SUBNET_OCID_HERE"

6. Get the Ubuntu 22.04 ARM image OCID

Note: Ubuntu 22.04 ARM64 is just an example here. You can use any image you want, as long as it is compatible with VM.Standard.A1.Flex in your region.

Run:

oci compute image list \
  --compartment-id "$COMPARTMENT_ID" \
  --operating-system "Canonical Ubuntu" \
  --operating-system-version "22.04" \
  --shape "VM.Standard.A1.Flex" \
  --sort-by TIMECREATED \
  --sort-order DESC \
  --all \
  --query "data[0].{name:\"display-name\",id:id}" \
  --output table

You should get an image like:

Canonical-Ubuntu-22.04-aarch64-YYYY.MM.DD-1

Set the image OCID:

IMAGE_ID="ocid1.image.oc1.REGION.YOUR_IMAGE_OCID_HERE"

7. Add your SSH public key to Cloud Shell

Create a public key file:

nano ~/oracle-a1.pub

Paste your public key. It should be one line:

ssh-ed25519 AAAAC3... oracle-a1

Save:

Ctrl + O
Enter
Ctrl + X

Verify it is one line:

wc -l ~/oracle-a1.pub

Expected:

1 /home/YOUR_USER/oracle-a1.pub

If it says more than 1, fix the file.


8. Create the retry script

Create the script:

nano ~/create-a1-flex.sh

Paste this script and replace the placeholder OCIDs/AD names with your own values.

#!/usr/bin/env bash
set -u

# ==========================================================
# Oracle A1 Flex Retry Launcher
#
# This script tries to create an Always Free A1 Flex instance.
# If Oracle returns "Out of host capacity", it tries the next AD.
# After trying all ADs, it sleeps a random amount of time and retries.
#
# Keep only ONE copy of this script running.
# ==========================================================

# Root compartment / tenancy OCID, or another compartment OCID.
COMPARTMENT_ID="ocid1.tenancy.oc1..YOUR_TENANCY_OCID_HERE"

# Public subnet OCID. Must be a PUBLIC subnet if you want public IPv4.
SUBNET_ID="ocid1.subnet.oc1.REGION.YOUR_PUBLIC_SUBNET_OCID_HERE"

# Image OCID for your region. Ubuntu 22.04 ARM64 is just one example.
IMAGE_ID="ocid1.image.oc1.REGION.YOUR_UBUNTU_2204_ARM_IMAGE_OCID_HERE"

# SSH public key file inside Cloud Shell.
SSH_PUBLIC_KEY_FILE="$HOME/oracle-a1.pub"

# Instance name shown in Oracle Console.
DISPLAY_NAME="a1-flex-instance"

# Full Always Free A1 allowance.
# If this never succeeds, try 2/12 or 1/6.
OCPUS=4
MEMORY_GB=24

# Boot volume settings.
# 100 GB is a comfortable size for general use.
BOOT_GB=100

# 20 VPU = higher performance than default balanced 10 VPU.
# If you want safest billing behavior, use 10 instead.
BOOT_VPU=20

# Your Availability Domain names.
# Get them from:
# oci iam availability-domain list --all --output table
ADS=(
  "YOUR_REGION_AD_1"
  "YOUR_REGION_AD_2"
  "YOUR_REGION_AD_3"
)

# Random delay between full retry rounds.
# The script tries all ADs, then sleeps 30-180 seconds.
MIN_SLEEP_SECONDS=30
MAX_SLEEP_SECONDS=180

# Stop early if SSH key file is missing.
if [ ! -f "$SSH_PUBLIC_KEY_FILE" ]; then
  echo "Missing SSH public key file: $SSH_PUBLIC_KEY_FILE"
  echo "Create it first, for example:"
  echo "nano ~/oracle-a1.pub"
  exit 1
fi

SSH_KEY="$(cat "$SSH_PUBLIC_KEY_FILE")"

echo "Starting OCI A1 retry launcher..."
echo "Display name: $DISPLAY_NAME"
echo "Shape: VM.Standard.A1.Flex"
echo "OCPUs: $OCPUS"
echo "Memory: ${MEMORY_GB} GB"
echo "Boot volume: ${BOOT_GB} GB"
echo "Boot VPU: ${BOOT_VPU}"
echo "Retry delay: random ${MIN_SLEEP_SECONDS}-${MAX_SLEEP_SECONDS} seconds"
echo

while true; do
  for AD in "${ADS[@]}"; do
    echo "[$(date)] Trying AD: $AD"

    # Try to launch the instance.
    # --assign-public-ip true requires a public subnet.
    # --wait-for-state RUNNING waits until the instance is running.
    OUTPUT="$(oci compute instance launch \
      --availability-domain "$AD" \
      --compartment-id "$COMPARTMENT_ID" \
      --shape "VM.Standard.A1.Flex" \
      --display-name "$DISPLAY_NAME" \
      --subnet-id "$SUBNET_ID" \
      --assign-public-ip true \
      --metadata "{\"ssh_authorized_keys\":\"$SSH_KEY\"}" \
      --shape-config "{\"ocpus\":$OCPUS,\"memoryInGBs\":$MEMORY_GB}" \
      --source-details "{\"sourceType\":\"image\",\"imageId\":\"$IMAGE_ID\",\"bootVolumeSizeInGBs\":$BOOT_GB,\"bootVolumeVpusPerGB\":$BOOT_VPU}" \
      --wait-for-state RUNNING \
      --max-wait-seconds 300 2>&1)"

    STATUS=$?

    if [ "$STATUS" -eq 0 ]; then
      echo
      echo "SUCCESS! Instance created and running."
      echo "$OUTPUT"
      exit 0
    fi

    echo "Failed in $AD"
    echo "$OUTPUT" | tail -n 12
    echo
  done

  # Random delay to avoid hitting the API at a fixed interval.
  SLEEP_SECONDS=$(( RANDOM % (MAX_SLEEP_SECONDS - MIN_SLEEP_SECONDS + 1) + MIN_SLEEP_SECONDS ))

  echo "[$(date)] No capacity in any AD. Sleeping $SLEEP_SECONDS seconds..."
  echo
  sleep "$SLEEP_SECONDS"
done

Save:

Ctrl + O
Enter
Ctrl + X

Make it executable:

chmod +x ~/create-a1-flex.sh

Run it:

~/create-a1-flex.sh

If it works, you will see:

SUCCESS! Instance created and running.

If it fails with Out of host capacity, that is normal. The script will keep retrying.


9. Keep it running with tmux

Cloud Shell can disconnect. Use tmux so the script keeps running during normal terminal disconnects.

Start a tmux session:

tmux new -s oracle-a1

Run the script inside tmux:

~/create-a1-flex.sh

Detach from tmux:

Ctrl + B
then press D

Later, open Cloud Shell again and reattach:

tmux attach -t oracle-a1

If Oracle recycled your Cloud Shell environment, the tmux session may be gone. In that case, start it again.


10. If bootVolumeVpusPerGB fails

Some accounts/CLI versions may reject this field.

If you see an error related to:

bootVolumeVpusPerGB

Edit the script:

nano ~/create-a1-flex.sh

Find this part:

\"bootVolumeVpusPerGB\":$BOOT_VPU

Remove it so --source-details becomes:

--source-details "{\"sourceType\":\"image\",\"imageId\":\"$IMAGE_ID\",\"bootVolumeSizeInGBs\":$BOOT_GB}"

Then rerun:

~/create-a1-flex.sh

11. If 4 OCPU / 24 GB never succeeds

Edit the script:

nano ~/create-a1-flex.sh

Try smaller sizes:

OCPUS=2
MEMORY_GB=12

Or:

OCPUS=1
MEMORY_GB=6

Smaller instances are more likely to find capacity.

Later, you can try resizing the instance back to:

4 OCPU / 24 GB RAM

12. After the instance is created

Go to:

Oracle Console → Compute → Instances

Check:

Shape: VM.Standard.A1.Flex
OCPU: 4
Memory: 24 GB
Public IPv4: Yes
Boot volume: 100 GB

At that point, the automation part is done: the instance exists, the shape is correct, and Oracle found capacity for it.


13. Final notes

This method does not guarantee capacity. It only automates the retry process using the official OCI CLI.

Keep it sane:

One script only
Do not run multiple copies
Do not retry every few seconds
Stop once the instance is created
Check Billing / Cost Analysis after creation

Oracle A1 Always Free is excellent when you get it, but the capacity issue is real. This script simply saves you from manually clicking Create over and over.

Comments (0)

Enter your name, 2-50 charactersEnter your comment, up to 1000 characters

Loading comments...