šŸš€ Setting Up Docker and Docker Compose on Oracle Cloudā€™s Always Free Tier Instance

Ā·

5 min read

Oracle Cloud Infrastructure (OCI) offers a generous Always Free Tier thatā€™s perfect for developers and homelab enthusiasts looking to run containerized applications. In this guide, Iā€™ll show you how to:

  1. Summarize the key benefits of the Always Free Tier.

  2. Set up Docker and Docker Compose on an ARM-based instance (VM.Standard.A1.Flex).

  3. Automate the installation using a wrapper script for easy deployments.


šŸŒŸ What You Get with Oracle Cloudā€™s Always Free Tier

Oracleā€™s Always Free resources are persistent and donā€™t expire, unlike other cloud providersā€™ time-limited trials. Hereā€™s what you get for free:

1. Compute Instances

  • VM.Standard.A1.Flex (ARM-based)

    • Up to 4 OCPUs and 24 GB RAM split across multiple instances.

    • Suitable for Docker containers, self-hosted applications, and development environments.

  • VM.Standard.E2.Micro (Intel/AMD-based)

    • 1 OCPU and 1 GB RAM.

    • Great for small services like web servers, monitoring tools, or DNS services.

2. Storage

  • 200 GB block storage (total): Attach to any compute instance.

  • 20 GB object storage: For static files or backups.

  • 10 GB archive storage: For long-term storage.

3. Autonomous Databases

  • 2 autonomous databases (20 GB each) for lightweight app backends or data analytics.

4. Networking

  • Virtual Cloud Network (VCN) with free load balancing (10 Mbps).

  • Site-to-Site VPN for connecting on-premise infrastructure to OCI.

āœ… Learn more: Oracle Always Free Tier Documentation


šŸ–„ļø Step-by-Step Guide: Setting Up Docker and Docker Compose

Weā€™ll set up Docker and Docker Compose on a VM.Standard.A1.Flex instance running Oracle Linux 8 or a compatible ARM-based Linux distribution.


Step 1: Provision an Always Free Instance

  1. Log in to your Oracle Cloud Console.

  2. Navigate to Compute > Instances and click Create Instance.

  3. Choose the VM.Standard.A1.Flex shape and allocate the following:

    • OCPUs: 2 (or up to 4 depending on your requirements)

    • RAM: 12 GB (or as needed)

    • Attach a 200 GB block volume (if desired).

  4. Complete the configuration and launch the instance.


Step 2: Update System Packages

SSH into your instance and run the following commands to update the package manager.

sudo yum update -y

Step 3: Install Docker

  1. Install required dependencies:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
  1. Add Dockerā€™s official repository:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  1. Install Docker:
sudo yum install -y docker-ce docker-ce-cli containerd.io
  1. Enable and start the Docker service:
sudo systemctl start docker
sudo systemctl enable docker
  1. Verify the installation:
docker run hello-world

Step 4: Install Docker Compose

Starting from Docker Compose v2, the Compose functionality is integrated into the Docker CLI, available through docker compose. However, if needed, you can also install the standalone version.

To check if Docker Compose is already available:

docker compose version

If the integrated version is present, youā€™re good to go! If not, follow the steps below to install the standalone version.


Step 5: Installing Standalone Docker Compose (Optional)

Download the latest version dynamically from GitHub:

DOCKER_COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep tag_name | cut -d '"' -f 4)
sudo curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Apply executable permissions:

sudo chmod +x /usr/local/bin/docker-compose

Verify the installation:

docker-compose version

Step 6: Enable Docker for Non-Root Users

By default, you need sudo to run Docker commands. To fix this, add your user to the docker group:

sudo usermod -aG docker $USER

Apply the changes by logging out and back in or running:

newgrp docker

Now you can run Docker commands without sudo:

docker version
docker compose version

Step 7: Automate the Installation with a Wrapper Script

Hereā€™s a complete wrapper script that installs Docker and Docker Compose, checks for existing installations, and configures non-root access.

#!/bin/bash

# Check for Docker installation
if ! [ -x "$(command -v docker)" ]; then
    echo "Docker not found. Installing Docker..."

    # Update system and install required dependencies
    sudo yum update -y
    sudo yum install -y yum-utils device-mapper-persistent-data lvm2

    # Add Docker repository
    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

    # Install Docker
    sudo yum install -y docker-ce docker-ce-cli containerd.io

    # Enable and start Docker
    sudo systemctl start docker
    sudo systemctl enable docker

    echo "Docker installed successfully."
else
    echo "Docker is already installed."
fi

# Check if user is already in the docker group
if groups $USER | grep &>/dev/null '\bdocker\b'; then
    echo "User $USER is already part of the docker group."
else
    echo "Adding $USER to the docker group..."
    sudo usermod -aG docker $USER
    echo "You must log out and log back in to use Docker without sudo."
fi

# Check for Docker Compose (plugin or standalone)
if docker compose version &>/dev/null; then
    echo "Docker Compose is already available via the Docker plugin:"
    docker compose version
else
    echo "Installing standalone Docker Compose..."

    # Get the latest version of Docker Compose
    DOCKER_COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep tag_name | cut -d '"' -f 4)

    # Download and install
    sudo curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose

    echo "Standalone Docker Compose installed successfully."
    docker-compose version
fi

echo "Docker and Docker Compose setup is complete. Remember to log out and log back in if needed."

Step 8: Run the Wrapper Script

  1. Save the script as install_docker.sh:
nano install_docker.sh
  1. Make it executable:
chmod +x install_docker.sh
  1. Run the script:
./install_docker.sh

āœ… Final Verification

After running the script, verify Docker and Docker Compose:

docker version
docker compose version

šŸŽ‰ Conclusion

Youā€™ve now set up Docker and Docker Compose on an ARM-based Oracle Cloud instance using the Always Free Tier! With this setup, you can:

  • Run containerized applications (e.g., Nginx, PostgreSQL, Redis).

  • Explore Kubernetes with microservices.

  • Host self-managed applications like Nextcloud or Home Assistant.

The possibilities are endless! šŸš€

Let me know in the comments if you tried this or if youā€™d like to see more cloud/container-related tutorials. šŸŒ

Ā