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:
from ads.jobs import Job, DataScienceJob, ContainerRuntime
job = (
Job(name="My Job")
.with_infrastructure(
DataScienceJob()
# Configure logging for getting the job run outputs.
.with_log_group_id("<log_group_ocid>")
# Log resource will be auto-generated if log ID is not specified.
.with_log_id("<log_ocid>")
# 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.
.with_compartment_id("<compartment_ocid>")
.with_project_id("<project_ocid>")
.with_subnet_id("<subnet_ocid>")
.with_shape_name("VM.Standard.E3.Flex")
# 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_block_storage_size(50)
)
.with_runtime(
ContainerRuntime()
.with_image("<region>.ocir.io/<tenancy>/<image>:<tag>")
.with_image_digest("<image_digest>")
.with_image_signature_id("<image_signature_id>")
.with_environment_variable(GREETINGS="Welcome to OCI Data Science")
.with_entrypoint(["/bin/sh", "-c"])
.with_cmd("sleep 5 && echo $GREETINGS")
)
)
kind: job
spec:
name: "My Job"
infrastructure:
kind: infrastructure
type: dataScienceJob
spec:
blockStorageSize: 50
compartmentId: <compartment_ocid>
jobInfrastructureType: STANDALONE
logGroupId: <log_group_ocid>
logId: <log_ocid>
projectId: <project_ocid>
shapeConfigDetails:
memoryInGBs: 16
ocpus: 1
shapeName: VM.Standard.E3.Flex
subnetId: <subnet_ocid>
runtime:
kind: runtime
type: container
spec:
cmd: sleep 5 && echo $GREETINGS
entrypoint:
- /bin/sh
- -c
env:
- name: GREETINGS
value: Welcome to OCI Data Science
image: <region>.ocir.io/<your_tenancy>/<your_image>
# Create the job on OCI Data Science
job.create()
# Start a job run
run = job.run()
# Stream the job run outputs
run.watch()
To configure ContainerRuntime, you must specify the container image.
Similar to other runtime, you can add environment variables.
You can optionally specify the entrypoint, cmd, image_digest and image_signature_id for running the container.
See also: