Build & use custom image

Explanations on how to build and use your own custom image

Last updated 10th June, 2021.

Objective

This tutorial covers the process of building your own job image for specific needs

Requirements

Write your own Dockerfile

Create a new file and name it Dockerfile

Choosing a base image

First you need to choose a base image to start from.

Header of your Dockerfile should look like this :

FROM <base-image>

If you want to be able to use GPU hardware on your AI TRAINING jobs, the base image should have cuda drivers installed on.

Here is a list of base images (including cuda drivers) that OVHcloud uses within notebooks :

For example if you want to start from the base image tensorflow/tensorflow:2.3.0-gpu :

FROM tensorflow/tensorflow:2.3.0-gpu

Install what you need

Bash command instructions on your Dockerfile should begin with RUN prefix.

Example if your want to install vim :

RUN apt-get update && apt-get install -y vim

You can copy files from your local directory inside docker image with the COPY prefix.

Example if you want to add the file example.txt at the root of the image :

COPY example.txt /example.txt

Images in AI Training are not run as root user, but by an "ovh" user with UID 42420. 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. You can do it with the following instruction :

RUN chown -R 42420:42420 <your-target-directory>

The home directory for the "ovh" user (with UID 42420) will be /workspace. If your base image (the one used by the FROM instruction) does not create the /workspace directory (and it probably doesn't if you didn't use an image provided by OVHcloud), then you should create it in your Dockerfile.

RUN mkdir -p /workspace && chown -R 42420:42420 /workspace
ENV HOME /workspace
WORKDIR /workspace

You can set environment variables with the ENV prefix.

Example if you want to add an environment variable KEY with value VALUE

ENV KEY VALUE

For more information about dockerfile we recommand you to refer to the official documentation

Build image

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 :

docker build . -t <image-identifier>

The dot . argument indicates that your build context (place of the Dockerfile and other needed files) is the current directory.

The -t argument allow you to choose the identifier to give to your image. Usually image identifiers are composed of a name and a version tag <name>:<version>.

Test it locally (Optional)

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

docker run --rm -it --user=42420:42420 <image-identifier>

Don't forget the --user=42420:42420 argument if you want to simulate the exact same behavior that will occur on AI TRAINING jobs. It executes the docker container as the specific OVHcloud user (user 42420:42420).

Push image in the registry of your choice

Pushing your image to a registry is needed in order for AI Training to pull it.

AI Training provides a default registry called Shared registry where users are able to push their custom images. It is linked with every project by default.

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 Training project before using it.

The basic commands to push a docker image to a registry is :

docker login -u <registry-user> -p <registry-password> <registry>
docker tag <image-identifier> <registry>/<image-identifier>
docker push <registry>/<image-identifier>

Example if you want to push an image named custom-image inside a registry registry.gra.training.ai.cloud.ovh.net :

docker login -u <registry-user> -p <registry-password> my-registry.ai.cloud.ovh.net
docker tag custom-image:latest my-registry.ai.cloud.ovh.net/custom-image:latest
docker push my-registry.ai.cloud.ovh.net/custom-image:latest

If you want to know the exact commands to push on the shared registry, please consult the Details button of the Shared Docker Registry section in the Home panel of AI Training.

image

Going further

A full Dockerfile example about building a Jupyter notebook image with Tensorflow is available on our example repository here.

Feedback

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


Did you find this guide useful?

Please feel free to give any suggestions in order to improve this documentation.

Whether your feedback is about images, content, or structure, please share it, so that we can improve it together.

Your support requests will not be processed via this form. To do this, please use the "Create a ticket" form.

Thank you. Your feedback has been received.


These guides might also interest you...

OVHcloud Community

Access your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.

Discuss with the OVHcloud community

In accordance with the 2006/112/CE Directive, modified on 01/01/2015, prices incl. VAT may vary according to the customer's country of residence
(by default, the prices displayed are inclusive of the UK VAT in force).