{{ head.image.alt }}

Solutions

Containers & Functions

Oracle Cloud Infrastructure (OCI) is a cloud platform that offers a range of services for modern application development and deployment. Among these services are OCI Containers and OCI Functions, which enable you to run your applications in a serverless and scalable way, without managing any infrastructure.

In this blog post, we will explain what OCI Containers and OCI Functions are, how they work, and how you can use them to build and run your applications on OCI.

What are OCI Containers?

OCI Containers are a service that allows you to run Docker containers on OCI without provisioning or managing any servers. You can use OCI Containers to run any application that can be packaged as a Docker image, such as web applications, microservices, batch jobs, or machine learning models.

OCI Containers are based on the open source Containerd project, which provides a lightweight runtime for containers. OCI Containers use the same API as Docker, so you can use the same tools and commands to interact with them.

OCI Containers offer the following benefits:

  • Serverless: You only pay for the resources you use while your containers are running. You don't pay for idle time or unused capacity.
  • Scalable: You can scale your containers up or down based on the demand for your application. You can also use autoscaling policies to automatically adjust the number of containers based on metrics such as CPU utilization or memory usage.
  • Secure: You can run your containers in isolated environments, separated from the host system and other containers. You can also use network security groups and policies to control the traffic between your containers and other resources on OCI.
  • Integrated: You can use OCI Container Registry (OCIR) to store and manage your Docker images. OCIR is a secure and performance image repository service that integrates with OCI Identity and Access Management (IAM) and OCI Audit. You can also use other OCI services with your containers, such as Object Storage, Database, or Events.

What are OCI Functions?

OCI Functions is a serverless compute service that lets you create, run, and scale functions on OCI. Functions are small pieces of code that perform a single task or logic, such as processing an event, transforming data, or calling an API.

OCI Functions is based on the open source Fn Project, which is a framework for building and running functions using any programming language. You can use the Fn CLI tool to create, deploy, and invoke functions on OCI Functions.

OCI Functions offer the following benefits:

  • Serverless: You only pay for the resources you use while your functions are executing. You don't pay for idle time or unused capacity.
  • Scalable: You can scale your functions up or down based on the demand for your application. You can also use autoscaling policies to automatically adjust the number of function instances based on metrics such as throughput or concurrency.
  • Secure: You can run your functions in isolated environments, separated from the host system and other functions. You can also use network security groups and policies to control the traffic between your functions and other resources on OCI.
  • Integrated: You can use OCIR to store and manage your function images. OCIR is a secure and performance image repository service that integrates with OCI IAM and OCI Audit. You can also use other OCI services with your functions, such as Object Storage, Database, Events, or API Gateway.

How to Use OCI Containers and Functions

To use OCI Containers and Functions, you need to have an OCI account and a tenancy. A tenancy is a secure and isolated environment where you can create and manage your resources on OCI.

You also need to have a Docker installation on your local machine to build and push your Docker images to OCIR. You can download Docker from https://www.docker.com/get-started.

To use OCI Containers, you need to do the following steps:

  1. Create a container image repository in OCIR. A container image repository is a collection of Docker images that share the same name but have different tags.
  2. Build your Docker image using the docker build command. Your Docker image should contain your application code, libraries, and dependencies.
  3. Push your Docker image to OCIR using the docker push command. You need to authenticate with OCIR using your OCI username and auth token.
  4. Create a container instance in OCI Console or using the oci container-instances container create command. A container instance is a running instance of your Docker image on OCI.
  5. Specify the configuration details for your container instance, such as the image name, memory size, CPU cores, network settings, environment variables, etc.
  6. Run your container instance using the oci container-instances container start command or by clicking the Start button in the Console.
  7. Monitor and manage your container instance using the OCI Console or the oci container-instances commands. You can view the logs, metrics, and events of your container instance, as well as stop, restart, or delete it.

To use OCI Functions, you need to do the following steps:

  1. Install the Fn CLI tool on your local machine using the curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh command.
  2. Initialize your function project using the fn init command. A function project is a directory that contains your function code, configuration files, and dependencies.
  3. Write your function code using your preferred programming language. You can use one of the Function Development Kits (FDKs) to simplify the development process and access the function context and input/output data.
  4. Test your function locally using the fn run command. This will build your function image and run it in a Docker container on your local machine.
  5. Deploy your function to OCI Functions using the fn deploy command. This will push your function image to OCIR and upload your function metadata to OCI Functions.
  6. Invoke your function on OCI Functions using the fn invoke command or by sending an HTTP request to the function's invoke endpoint. You can also trigger your function from other OCI services or external services using events or webhooks.
  7. Monitor and manage your function using the OCI Console or the fn commands. You can view the logs, metrics, and events of your function, as well as update, delete, or list it.

Conclusion

OCI Containers and Functions are powerful services that enable you to run your applications in a serverless and scalable way, without managing any infrastructure. You can use OCI Containers and Functions to build and run any type of application, such as web applications, microservices, batch jobs, or machine learning models.