Run a ContainerΒΆ

The ContainerRuntime class allows you to run a container image using OCI data science jobs.

OCI Container Registry

To use the ContainerRuntime, you need to first push the image to OCI container registry.

Note that you cannot build a docker image inside an OCI Data Science Notebook Session.

For more details, see:

Here is an example to create and run a container job:

  • Python
  • YAML
from import Job, DataScienceJob, ContainerRuntime

job = (
    Job(name="My Job")
        # Configure logging for getting the job run outputs.
        # Log resource will be auto-generated if log ID is not specified.
        # If you are in an OCI data science notebook session,
        # the following configurations are not required.
        # Configurations from the notebook session will be used as defaults.
        # Shape config details are applicable only for the flexible shapes.
        .with_shape_config_details(memory_in_gbs=16, ocpus=1)
        # Minimum/Default block storage size is 50 (GB).
        .with_environment_variable(GREETINGS="Welcome to OCI Data Science")
        .with_entrypoint(["/bin/sh", "-c"])
        .with_cmd("sleep 5 && echo $GREETINGS")
kind: job
  name: "My Job"
    kind: infrastructure
    type: dataScienceJob
      blockStorageSize: 50
      compartmentId: <compartment_ocid>
      jobInfrastructureType: STANDALONE
      logGroupId: <log_group_ocid>
      logId: <log_ocid>
      projectId: <project_ocid>
        memoryInGBs: 16
        ocpus: 1
      shapeName: VM.Standard.E3.Flex
      subnetId: <subnet_ocid>
    kind: runtime
    type: container
      cmd: sleep 5 && echo $GREETINGS
      - /bin/sh
      - -c
      - name: GREETINGS
        value: Welcome to OCI Data Science
      image: <region><your_tenancy>/<your_image>
# Create the job on OCI Data Science
# Start a job run
run =
# Stream the job run outputs

To configure ContainerRuntime, you must specify the container image. Similar to other runtime, you can add environment variables. You can optionally specify the entrypoint and cmd for running the container.

See also: