AI Training - Tutorial - Build & use custom Docker image
Explanations on how to build and use your own custom image
Explanations on how to build and use your own custom image
Last updated 31st January, 2023.
This tutorial covers the process of building your own job image for specific needs
Create a new file and name it Dockerfile
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
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
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>
.
Please make sure that the docker image you will push in order to run containers using AI products respects the linux/AMD64 target architecture. You could, for instance, build your image using buildx as follows:
docker buildx build --platform linux/amd64 ...
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).
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.
A full Dockerfile example about building a Jupyter notebook image with Tensorflow is available on our example repository here.
Please send us your questions, feedback and suggestions to improve the service:
Prima di inviare la valutazione, proponici dei suggerimenti per migliorare la documentazione.
Immagini, contenuti, struttura... Spiegaci perché, così possiamo migliorarla insieme!
Le richieste di assistenza non sono gestite con questo form. Se ti serve supporto, utilizza il form "Crea un ticket" .
Grazie per averci inviato il tuo feedback.
Accedi al tuo spazio nella Community Fai domande, cerca informazioni, pubblica contenuti e interagisci con gli altri membri della Community OVHcloud
Discuss with the OVHcloud community