Note:

Use OCI Container Instances to schedule start and stop for OCI Compute Instances

Introduction

Oracle Cloud Infrastructure (OCI) Container Instances is a serverless compute service that enables you to quickly and easily run containers without managing any servers.

You can use the OCI Compute service to create bare metal compute or virtual machine (VM) instances to deploy and run your applications. OCI Compute lets you provision and manage compute hosts, known as instances.

This tutorial describes an example about how to use Container Instances to manage the lifecycle state of Compute Instances in a compartment (it can be extended to tenancy as well). There are cases when you need an automated way to schedule stop/start of Compute Instances – like a crontab job. For example, you need some of your compute instances to run during the day and to stop them during the night to save on cost. This sort of “crontab” job can be created using the OCI Container Instance service.

Basically, the container instance runs Python code looking for a specific freeform tag in each compute instance in a compartment, in a loop. If it finds the specific tag, it will compare the tag value with the current time (when the script runs) to establish if the compute instance should be in running or stopped state at that time and decides to stop or start the compute instance.

Objectives

Prerequisites

Task 1: Create a dynamic group to allow Container Instance to manage Compute Instances

Task 2: Create a policy to allow resources in dynamic group to manage compute instances

Task 3: Build the Docker image

Task 4: Upload the image to Oracle Cloud Infrastructure Registry

Task 5: Define freeform tag on compute instance

Task 6: Create the container instance

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.