Skip to content

Commit 02f39e7

Browse files
committed
Merge branch 'BV-AI-deploy-docker-image' of https://github.com/ovh/docs into BV-AI-deploy-docker-image
2 parents 7ecedda + 5729710 commit 02f39e7

File tree

1 file changed

+44
-45
lines changed

1 file changed

+44
-45
lines changed

pages/platform/ai/deploy_tuto_12_build_custom_image/guide.en-gb.md

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: AI Deploy - Tutorial - Build & use custom Docker image
2+
title: AI Deploy - Tutorial - Build & use a custom Docker image
33
slug: deploy/build-use-custom-image
44
excerpt: Explanations on how to build and use your own custom image
55
section: AI Deploy - Tutorials
@@ -11,22 +11,22 @@ updated: 2023-03-29
1111

1212
## Objective
1313

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.
1515

1616
## Requirements
1717

1818
- Access to the [OVHcloud Control Panel](https://www.ovh.com/auth/?action=gotomanager&from=https://www.ovh.co.uk/&ovhSubsidiary=GB)
1919
- A **Public Cloud** project
2020
- 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/))
2323

2424
## Quick overview
2525

2626
AI Deploy main goal is to simplify AI models or applications deployment, release them in production, with resiliency and security, in a few seconds.
2727
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.
2828

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.
3030
The Docker images that you build can be deployed locally, with OVHcloud AI Deploy but also with cloud competitors such as AWS or GCP.
3131

3232
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
4444
Instead of starting from scratch, feel free to start from an existing Docker image, as long as it is compliant with the following guidelines.
4545
For example, you can start from 'python', from 'alpine' or equivalent.
4646

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.
4848

4949
### Use specific images with CUDA drivers for GPUs
5050

5151
> [!primary]
5252
>
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**.
5454
5555
Here is a potential list of official base images (featuring **cuda drivers**) that you can use:
5656

5757
- [pytorch/pytorch:latest](https://hub.docker.com/r/pytorch/pytorch)
5858
- [tensorflow/tensorflow:latest-gpu](https://hub.docker.com/r/tensorflow/tensorflow)
59-
- [huggingface/transformers-pytorch-gpu:latest](https://hub.docker.com/r/huggingface/transformers-pytorch-gpu/) docker pull huggingface/transformers-pytorch-gpu:latest
59+
- [huggingface/transformers-pytorch-gpu:latest](https://hub.docker.com/r/huggingface/transformers-pytorch-gpu/) (docker pull huggingface/transformers-pytorch-gpu:latest)
6060
- [mxnet/python](https://hub.docker.com/r/mxnet/python)
6161
- [nvidia/cuda](https://hub.docker.com/r/nvidia/cuda)
6262

63-
For example if you want to start from the base image `tensorflow/tensorflow:latest-gpu`:
63+
For example, if you want to start from the base image `tensorflow/tensorflow:latest-gpu`:
6464

6565
```{.console}
6666
FROM tensorflow/tensorflow:latest-gpu
6767
```
6868

6969
### Use the linux/amd64 architecture
7070

71-
Your Docker image has to support at least `linux/amd64` platform to be deployed correctly. Otherwise deployment will fail.
71+
Your Docker image has to support at least the `linux/amd64` platform to be deployed correctly. Otherwise deployment will fail.
7272

7373
When you invoke a build, you can set the `--platform` flag to specify the target platform for the build output, `linux/amd64`.
74-
This is especially relevant if you use Apple new computers (M1/M2/... chipsets) or ARM-based computers.
74+
This is especially relevant if you use newer Apple computers (M1/M2/... chipsets) or ARM-based computers.
7575

7676
```{.console}
7777
docker buildx build --platform linux/amd64,linux/arm64 ...
@@ -81,12 +81,12 @@ More information can be found in the [official Docker documentation](https://doc
8181

8282
### Create an OVHcloud user and a working directory
8383

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**.
8585
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.
8686

87-
This is the case in the vast majority of use-cases.
87+
This is the case in the vast majority of use cases.
8888

89-
You can do it with the following instruction:
89+
You can do it with the following instructions:
9090

9191

9292
```{.console}
@@ -128,24 +128,24 @@ RUN pip install -r requirements.txt
128128
### Manage output data effectively (S3, ...)
129129

130130
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.
132132

133133
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.
135135

136136
Be careful, **if you write data directly in your working directory, it will be lost when you stop your application**.
137137

138138
### Use environment variables for dynamic values
139139

140140
> [!primary]
141141
>
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/).
143143
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.
145145

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.
147147

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:
149149

150150
```
151151
ovhai run app <my_docker_image> -e LANGUAGE=english TOKEN=12345678
@@ -172,35 +172,34 @@ ADD . $foo
172172
### Exposing your model or application with an API
173173

174174
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]().
175176

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/).
179178

180179
### Exposing your application with a web frontend
181180

182181
While an API is useful for automation and code, sometimes you will need to expose your application or model through a web interface.
183182

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/).
186184
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/).
188185

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
190189

191-
Here, we will build a basic docker image, following the guidelines.
190+
Here we will build a basic Docker image, following the guidelines.
192191

193192
### Prepare the Dockerfile
194193

195-
Create a new file and name it `Dockerfile` following guidelines.
194+
Create a new file and name it `Dockerfile`, following the guidelines.
196195

197196
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.
202201

203-
A basic example can be summarized like this:
202+
A basic example can be summarised like this:
204203

205204
```{.console}
206205
# 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
216215
ADD example.py /workspace/
217216
ADD dataset.csv /workspace/
218217
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
220219
RUN chown -R 42420:42420 /workspace
221220
ENV HOME=/workspace
222221
@@ -226,28 +225,28 @@ CMD [ "python3" , "/workspace/example.py" ]
226225

227226
### Build your Docker image
228227

229-
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:
230229

231230
```{.console}
232231
docker build . -t <image-identifier>
233232
```
234233

235234
> [!primary]
236235
>
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.
238237
239238
> [!primary]
240239
>
241240
> 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>`.
242241
243242
> [!warning]
244243
>
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:
246245
>
247246
> `docker buildx build --platform linux/amd64 ...`
248247
>
249248
250-
## Test it locally (Optional)
249+
## Test it locally (optional)
251250

252251
If you want to verify that your built image is working properly, run the following command:
253252

@@ -257,17 +256,17 @@ docker run --rm -it --user=42420:42420 <image-identifier>
257256

258257
> [!warning]
259258
>
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**).
261260
262-
### Push image in the registry of your choice
261+
### Push the image to the registry of your choice
263262

264263
Pushing your image to a registry is needed in order for AI Deploy to pull it.
265264

266265
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.
267266

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.
269268

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:
271270

272271
```{.console}
273272
# Add a new registry into OVHcloud AI Tools
@@ -279,7 +278,7 @@ docker tag <image-identifier> <registry>/<image-identifier>
279278
docker push <registry>/<image-identifier>
280279
```
281280

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`:
283282

284283
```{.console}
285284
# 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
303302

304303
Please send us your questions, feedback and suggestions to improve the service:
305304

306-
- On the OVHcloud [Discord server](https://discord.gg/ovhcloud)
305+
- On the OVHcloud [Discord server](https://discord.gg/ovhcloud)

0 commit comments

Comments
 (0)