You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/platform/ai/deploy_tuto_12_build_custom_image/guide.en-gb.md
+44-45Lines changed: 44 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: AI Deploy - Tutorial - Build & use custom Docker image
2
+
title: AI Deploy - Tutorial - Build & use a custom Docker image
3
3
slug: deploy/build-use-custom-image
4
4
excerpt: Explanations on how to build and use your own custom image
5
5
section: AI Deploy - Tutorials
@@ -11,22 +11,22 @@ updated: 2023-03-29
11
11
12
12
## Objective
13
13
14
-
This tutorial covers the process of building your own Docker image for AI deploy. After detailing major guidelines, we will cover a quick example.
14
+
This tutorial covers the process of building your own Docker image for AI Deploy. After detailing major guidelines, we will cover a quick example.
15
15
16
16
## Requirements
17
17
18
18
- Access to the [OVHcloud Control Panel](https://www.ovh.com/auth/?action=gotomanager&from=https://www.ovh.co.uk/&ovhSubsidiary=GB)
19
19
- A **Public Cloud** project
20
20
- A [user for AI Deploy](https://docs.ovh.com/gb/en/publiccloud/ai/users)
21
-
-[Docker](https://www.docker.com/get-started) installed somewhere like your personal computer or a virtual machine
22
-
-Some knowledge about building an image. Follow [official Docker Getting Started](https://docs.docker.com/get-started/)
21
+
-[Docker](https://www.docker.com/get-started) installed on a personal computer or a virtual machine
22
+
-Knowledge about building a Docker image (see the [official Getting Started guide](https://docs.docker.com/get-started/))
23
23
24
24
## Quick overview
25
25
26
26
AI Deploy main goal is to simplify AI models or applications deployment, release them in production, with resiliency and security, in a few seconds.
27
27
Each application is linked to compute resources such as CPUs or GPUs, and can be accessed through an HTTP Endpoint provided by AI Deploy for each app.
28
28
29
-
In order to be deployed, your model or application **has to be containerized**, inside a Docker image. Containers provide isolation but also flexibility for your deployments.
29
+
In order to be deployed, your model or application **has to be containerised**, inside a Docker image. Containers provide isolation but also flexibility for your deployments.
30
30
The Docker images that you build can be deployed locally, with OVHcloud AI Deploy but also with cloud competitors such as AWS or GCP.
31
31
32
32
Inside your Docker image, you are free to install almost anything and everything as long as you follow guidelines below.
@@ -44,34 +44,34 @@ AI Deploy accept images from **public** or **private** repositories. In short, w
44
44
Instead of starting from scratch, feel free to start from an existing Docker image, as long as it is compliant with the following guidelines.
45
45
For example, you can start from 'python', from 'alpine' or equivalent.
46
46
47
-
If you need to work with GPU, please read the next paragraph.
47
+
If you need to work with GPUs, please read the next paragraph.
48
48
49
49
### Use specific images with CUDA drivers for GPUs
50
50
51
51
> [!primary]
52
52
>
53
-
> If you want to communicate with our **GPU** hardware in your **AI Deploy apps**, the base image should have **cuda drivers installed on**.
53
+
> If you want to communicate with our **GPU** hardware in your **AI Deploy apps**, the base image should have **cuda drivers installed**.
54
54
55
55
Here is a potential list of official base images (featuring **cuda drivers**) that you can use:
@@ -81,12 +81,12 @@ More information can be found in the [official Docker documentation](https://doc
81
81
82
82
### Create an OVHcloud user and a working directory
83
83
84
-
Deployed containers are not run as root user, but by an “OVHcloud” user with **UID 42420**.
84
+
Deployed containers are not run as root, but by an “OVHcloud” user with **UID 42420**.
85
85
It means that if you want to be able to write in a specific directory at runtime, you will have to give it specific rights.
86
86
87
-
This is the case in the vast majority of use-cases.
87
+
This is the case in the vast majority of usecases.
88
88
89
-
You can do it with the following instruction:
89
+
You can do it with the following instructions:
90
90
91
91
92
92
```{.console}
@@ -128,24 +128,24 @@ RUN pip install -r requirements.txt
128
128
### Manage output data effectively (S3, ...)
129
129
130
130
Just like AI Notebooks and AI Training, AI Deploy is easily connected to remote storage such as S3 object storage containers at launch.
131
-
However, unlike AI Notebooks and AI Training, AI Deploy **does NOT**synchronize data back to your remote storage.
131
+
However, unlike AI Notebooks and AI Training, AI Deploy **does NOT**synchronise data back to your remote storage.
132
132
133
133
If you need to write data somewhere, for example output from your AI model (generated images), your code application should include storage connection.
134
-
For example, you can use Python `Boto3` library when using Python and S3.
134
+
For example, you can use the Python `Boto3` library when using Python and S3.
135
135
136
136
Be careful, **if you write data directly in your working directory, it will be lost when you stop your application**.
137
137
138
138
### Use environment variables for dynamic values
139
139
140
140
> [!primary]
141
141
>
142
-
> For sensitive data such as password or token, consider using [Docker Secrets](https://docs.docker.com/engine/swarm/secrets/).
142
+
> For sensitive data such as passwords or tokens, consider using [Docker Secrets](https://docs.docker.com/engine/swarm/secrets/).
143
143
144
-
Sometimes, instead of hardcoding a variable inside a Dockerfile, it is much more powerful to pass variables during deployment. Docker provides natively this option with`--env` argument, and OVHcloud AI tools follow the same logic.
144
+
Sometimes, instead of hardcoding a variable inside a Dockerfile, it is much more powerful to pass variables during deployment. Docker provides this option natively through the`--env` argument, and OVHcloud AI tools follow the same logic.
145
145
146
-
During AI Deploy app creation, you will be able to pass environment variables via CLI, API or UI in the control panel. In your Dockerfile, you can gather theses variables with the `ENV` value
146
+
During AI Deploy app creation, you will be able to pass environment variables via CLI, API or UI in the control panel. In your Dockerfile, you can gather theses variables with the `ENV` value.
147
147
148
-
For example, you can launch a new app with two variable like this:
148
+
For example, you can launch a new app with two variables like this:
149
149
150
150
```
151
151
ovhai run app <my_docker_image> -e LANGUAGE=english TOKEN=12345678
@@ -172,35 +172,34 @@ ADD . $foo
172
172
### Exposing your model or application with an API
173
173
174
174
Inside your Dockerfile, you will need to expose your model or application so anyone can use it. The easiest way is to expose API via REST endpoint.
175
+
The most popular open source frameworks for exposing APIs are [Flask]() and [Fast API]().
175
176
176
-
Most famous and open source frameworks for exposing API are [Flask](https://flask.palletsprojects.com/) and [FastAPI](https://fastapi.tiangolo.com/).
177
-
178
-
You can find a basic example in the next chapter, and more advanced tutorials in [AI Deploy documentation](https://docs.ovh.com/gb/en/publiccloud/ai/).
177
+
You can find a basic example in the section below, and more advanced tutorials in our [AI Deploy documentation](https://docs.ovh.com/gb/en/publiccloud/ai/).
179
178
180
179
### Exposing your application with a web frontend
181
180
182
181
While an API is useful for automation and code, sometimes you will need to expose your application or model through a web interface.
183
182
184
-
AI Deploy is fully compliant with multiple frontend frameworks, such as [Streamlit](https://streamlit.io/), [Gradio](https://gradio.app/) or [Taipy](https://www.taipy.io/
185
-
).
183
+
AI Deploy is fully compliant with multiple frontend frameworks, such as [Streamlit](https://streamlit.io/), [Gradio](https://gradio.app/) or [Taipy](https://www.taipy.io/).
186
184
You can of course also build your own frontend with your favourite tools, such as HTML/CSS.
187
-
You can find a basic example in the next chapter, and more advanced tutorials in [AI Deploy documentation](https://docs.ovh.com/gb/en/publiccloud/ai/).
188
185
189
-
## Basic example: write your own Dockerfile and build your image
186
+
You can find a basic example in the section below, and more advanced tutorials in our [AI Deploy documentation](https://docs.ovh.com/gb/en/publiccloud/ai/).
187
+
188
+
## Basic example: Write your own Dockerfile and build your image
190
189
191
-
Here, we will build a basic docker image, following the guidelines.
190
+
Here we will build a basic Docker image, following the guidelines.
192
191
193
192
### Prepare the Dockerfile
194
193
195
-
Create a new file and name it `Dockerfile` following guidelines.
194
+
Create a new file and name it `Dockerfile`, following the guidelines.
196
195
197
196
1. First you need to choose a base image to start from.
198
-
2. Install what you need as dependencies with `apt` or `pip`. Bash command instructions on your Dockerfile should begin with `RUN` prefix.
199
-
3. Copy files from your local directory inside docker image with the `COPY` prefix.
200
-
4. Allow user OVHcloud UID 42420 to get specific rights
201
-
5. Run your script
197
+
2. Install what you need as dependencies with `apt` or `pip`. Bash command instructions on your Dockerfile should begin with the `RUN` prefix.
198
+
3. Copy files from your local directory inside the Docker image with the `COPY` prefix.
199
+
4. Allow user "OVHcloud UID 42420" to get specific rights.
200
+
5. Run your script.
202
201
203
-
A basic example can be summarized like this:
202
+
A basic example can be summarised like this:
204
203
205
204
```{.console}
206
205
# Start from official Python image since we don't need GPU
@@ -216,7 +215,7 @@ RUN apt-get update && apt-get install -y vim git
216
215
ADD example.py /workspace/
217
216
ADD dataset.csv /workspace/
218
217
219
-
# Create a HOME dedicated to the OVHcloud user (42420:42420). mandatory step
218
+
# Create a HOME dedicated to the OVHcloud user (42420:42420). Mandatory step
Once your **Dockerfile** is complete and match your needs, you have to choose a name and build the image using the following command in the same directory:
228
+
Once your **Dockerfile** is complete and matches your needs, you have to choose a name and build the image using the following command in the same directory:
230
229
231
230
```{.console}
232
231
docker build . -t <image-identifier>
233
232
```
234
233
235
234
> [!primary]
236
235
>
237
-
> The dot `.` argument indicates that your build context (place of the **Dockerfile** and other needed files) is the current directory.
236
+
> The dot argument `.` indicates that your build context (place of the **Dockerfile** and other needed files) is the current directory.
238
237
239
238
> [!primary]
240
239
>
241
240
> The `-t` argument allows you to choose the identifier to give to your image. Usually, image identifiers are composed of a **name** and a **version tag**`<name>:<version>`.
242
241
243
242
> [!warning]
244
243
>
245
-
> Please make sure that the docker image you will push in order to run containers using AI products respects the **linux/amd64** architecture. You could, for instance, build your image using **buildx** as follows:
244
+
> Please make sure that the Docker image you will push in order to run containers using AI products respects the **linux/amd64** architecture. You could, for instance, build your image using **buildx** as follows:
If you want to verify that your built image is working properly, run the following command:
253
252
@@ -257,17 +256,17 @@ docker run --rm -it --user=42420:42420 <image-identifier>
257
256
258
257
> [!warning]
259
258
>
260
-
> Don't forget the `--user=42420:42420` argument if you want to simulate the exact same behavior that will occur on **AI Deploy apps**. It executes the docker container as the specific OVHcloud user (user **42420:42420**).
259
+
> Don't forget the `--user=42420:42420` argument if you want to simulate the exact same behaviour that will occur on **AI Deploy apps**. It executes the Docker container as the specific OVHcloud user (user **42420:42420**).
261
260
262
-
### Push image in the registry of your choice
261
+
### Push the image to the registry of your choice
263
262
264
263
Pushing your image to a registry is needed in order for AI Deploy to pull it.
265
264
266
265
AI Deploy provides a default registry called **Shared registry** where users are able to push their custom images. It is linked with every project by default.
267
266
268
-
If you prefer using your own private docker registry instead of the shared one, feel free to use it. Just don't forget to [add your registry in your AI Tools project](https://docs.ovh.com/gb/en/publiccloud/ai/training/add-private-registry) before using it.
267
+
If you prefer using your own private Docker registry instead of the shared one, feel free to use it. Just don't forget to [add your registry in your AI Tools project](https://docs.ovh.com/gb/en/publiccloud/ai/training/add-private-registry) before using it.
269
268
270
-
The basic commands to push a docker image to a registry is:
269
+
The basic commands to push a Docker image to a registry is:
271
270
272
271
```{.console}
273
272
# Add a new registry into OVHcloud AI Tools
@@ -279,7 +278,7 @@ docker tag <image-identifier> <registry>/<image-identifier>
279
278
docker push <registry>/<image-identifier>
280
279
```
281
280
282
-
Example: if you want to push an image named `custom-image` inside a registry `registry.gra.training.ai.cloud.ovh.net`:
281
+
Example: If you want to push an image named `custom-image` inside a registry `registry.gra.training.ai.cloud.ovh.net`:
283
282
284
283
```{.console}
285
284
# Add a new registry into OVHcloud AI Tools
@@ -303,4 +302,4 @@ If you want to know the exact commands to push on the shared registry, please co
303
302
304
303
Please send us your questions, feedback and suggestions to improve the service:
305
304
306
-
- On the OVHcloud [Discord server](https://discord.gg/ovhcloud)
305
+
- On the OVHcloud [Discord server](https://discord.gg/ovhcloud)
0 commit comments