|
1 | 1 | Run a Container |
2 | 2 | *************** |
3 | 3 |
|
4 | | -The ADS ``ContainerRuntime`` class allows you to run a container image using OCI data science jobs. |
| 4 | +The :py:class:`~ads.jobs.ContainerRuntime` class allows you to run a container image using OCI data science jobs. |
5 | 5 |
|
6 | | -To use the ``ContainerRuntime``, you need to first push the image to `OCI container registry <https://docs.oracle.com/en-us/iaas/Content/Registry/Concepts/registryoverview.htm>`_. See `Creating a Repository <https://docs.oracle.com/en-us/iaas/Content/Registry/Tasks/registrycreatingarepository.htm>`_ and `Pushing Images Using the Docker CLI <https://docs.oracle.com/en-us/iaas/Content/Registry/Tasks/registrycreatingarepository.htm>`_ for more details. |
| 6 | +.. admonition:: OCI Container Registry |
7 | 7 |
|
8 | | -Python |
9 | | -====== |
| 8 | + To use the :py:class:`~ads.jobs.ContainerRuntime`, you need to first push the image to |
| 9 | + `OCI container registry <https://docs.oracle.com/en-us/iaas/Content/Registry/Concepts/registryoverview.htm>`_. |
| 10 | + For more details, see: |
| 11 | + |
| 12 | + * `Creating a Repository <https://docs.oracle.com/en-us/iaas/Content/Registry/Tasks/registrycreatingarepository.htm>`_ |
| 13 | + * `Pushing Images Using the Docker CLI <https://docs.oracle.com/en-us/iaas/Content/Registry/Tasks/registrycreatingarepository.htm>`_. |
10 | 14 |
|
11 | | -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 `Understand how CMD and ENTRYPOINT interact <https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact>`_). |
| 15 | +Here is an example to create and run a container job: |
12 | 16 |
|
13 | | -.. code-block:: python3 |
| 17 | +.. include:: ../jobs/tabs/container_runtime.rst |
14 | 18 |
|
15 | | - from ads.jobs import Job, DataScienceJob, ContainerRuntime |
| 19 | +To configure ``ContainerRuntime``, you must specify the container ``image``. |
| 20 | +Similar to other runtime, you can add environment variables. |
| 21 | +You can optionally specify the `entrypoint` and `cmd` for running the container. |
16 | 22 |
|
17 | | - job = ( |
18 | | - Job() |
19 | | - .with_infrastructure( |
20 | | - DataScienceJob() |
21 | | - .with_log_group_id("<log_group_ocid>") |
22 | | - .with_log_id("<log_ocid>") |
23 | | - # The following infrastructure configurations are optional |
24 | | - # if you are in an OCI data science notebook session. |
25 | | - # The configurations of the notebook session will be used as defaults |
26 | | - .with_compartment_id("<compartment_ocid>") |
27 | | - .with_project_id("<project_ocid>") |
28 | | - .with_subnet_id("<subnet_ocid>") |
29 | | - .with_shape_name("VM.Standard.E3.Flex") |
30 | | - .with_shape_config_details(memory_in_gbs=16, ocpus=1) # Applicable only for the flexible shapes |
31 | | - .with_block_storage_size(50) |
32 | | - ) |
33 | | - .with_runtime( |
34 | | - ContainerRuntime() |
35 | | - .with_image("<region>.ocir.io/<your_tenancy>/<your_image>") |
36 | | - .with_environment_variable(GREETINGS="Welcome to OCI Data Science") |
37 | | - .with_entrypoint(["/bin/sh", "-c"]) |
38 | | - .with_cmd("sleep 5 && echo $GREETINGS") |
39 | | - ) |
40 | | - ) |
41 | | -
|
42 | | - # Create the job with OCI |
43 | | - job.create() |
44 | | - # Run the job and stream the outputs |
45 | | - job_run = job.run().watch() |
46 | | -
|
47 | | -YAML |
48 | | -==== |
49 | | - |
50 | | -You could use the following YAML to create the same job: |
51 | | - |
52 | | -.. code-block:: yaml |
53 | | -
|
54 | | - kind: job |
55 | | - spec: |
56 | | - name: container-job |
57 | | - infrastructure: |
58 | | - kind: infrastructure |
59 | | - type: dataScienceJob |
60 | | - spec: |
61 | | - logGroupId: <log_group_ocid> |
62 | | - logId: <log_ocid> |
63 | | - compartmentId: <compartment_ocid> |
64 | | - projectId: <project_ocid> |
65 | | - subnetId: <subnet_ocid> |
66 | | - shapeName: VM.Standard.E3.Flex |
67 | | - shapeConfigDetails: |
68 | | - memoryInGBs: 16 |
69 | | - ocpus: 1 |
70 | | - blockStorageSize: 50 |
71 | | - runtime: |
72 | | - kind: runtime |
73 | | - type: container |
74 | | - spec: |
75 | | - image: iad.ocir.io/<your_tenancy>/<your_image> |
76 | | - cmd: |
77 | | - - sleep 5 && echo $GREETINGS |
78 | | - entrypoint: |
79 | | - - /bin/sh |
80 | | - - -c |
81 | | - env: |
82 | | - - name: GREETINGS |
83 | | - value: Welcome to OCI Data Science |
84 | | -
|
85 | | -**ContainerRuntime Schema** |
86 | | - |
87 | | -.. code-block:: yaml |
88 | | -
|
89 | | - kind: |
90 | | - required: true |
91 | | - type: string |
92 | | - allowed: |
93 | | - - runtime |
94 | | - type: |
95 | | - required: true |
96 | | - type: string |
97 | | - allowed: |
98 | | - - container |
99 | | - spec: |
100 | | - type: dict |
101 | | - required: true |
102 | | - schema: |
103 | | - image: |
104 | | - required: true |
105 | | - type: string |
106 | | - entrypoint: |
107 | | - required: false |
108 | | - type: |
109 | | - - string |
110 | | - - list |
111 | | - cmd: |
112 | | - required: false |
113 | | - type: |
114 | | - - string |
115 | | - - list |
116 | | - env: |
117 | | - nullable: true |
118 | | - required: false |
119 | | - type: list |
120 | | - schema: |
121 | | - type: dict |
122 | | - schema: |
123 | | - name: |
124 | | - type: string |
125 | | - value: |
126 | | - type: |
127 | | - - number |
128 | | - - string |
| 23 | +See also: |
129 | 24 |
|
| 25 | +* `Understand how CMD and ENTRYPOINT interact <https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact>`_ |
| 26 | +* `Bring Your Own Container <https://docs.oracle.com/en-us/iaas/data-science/using/jobs-byoc.htm>`_ |
0 commit comments