Custom Docker images

How to create and use your own docker image

Create your docker image

A docker image is created from a Dockerfile that describes the different steps to build it. You can find all the details in the official documentation. Below is a quick example of an image based on ubuntu with the hello program installed in it:

FROM ubuntu:18.04

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

CMD hello

Next, you will need to build the image and push it to a registry, for example Docker Hub (you will need to create an account, and create a new private or public repository).

docker build -t "<your_account_id>/hello-world:1.0.0" .
docker push "<your_account_id>/hello-world:1.0.0"

How to use your image

To use your image, you will need to use a generic docker profile  like docker-batch or docker-network (more profile available on the docker documentation).

Then, use the following constants:

Here is an example:

Python

import qarnot

conn = qarnot.connection.Connection(client_token='<<<MY_SECRET_TOKEN>>>')

task = conn.create_task('Private image', 'docker-batch')

task.constants['DOCKER_REPO'] = '<your_account_id>/hello-world'
task.constants['DOCKER_TAG'] = '1.0.0'
task.constants['DOCKER_REGISTRY_LOGIN'] = 'your_docker_hub_login'
task.constants['DOCKER_REGISTRY_PASSWORD'] = 'your_docker_hub_password'

task.run()
print(task.stdout())

Bash

#!/bin/bash

export QARNOT_CLIENT_TOKEN=<MY_SECRET_TOKEN>

qarnot task create \
--name "Private image" \
--profile "docker-batch" \
--instance 1 \
--constants \
  "DOCKER_REPO=<your_account_id>/hello-world" \
  "DOCKER_TAG=1.0.0" \
  "DOCKER_REGISTRY_LOGIN=your_docker_hub_login" \
  "DOCKER_REGISTRY_PASSWORD=your_docker_hub_password"

Using another Docker registry

To use a different Docker registry than the Docker hub, you just have to change the DOCKER_SRV constant, with the URL of the registry. For instance to pull an image from the Quay registry, add the following line:

task.constants['DOCKER_SRV'] ='https://quay.io'

Here is a complete example:

Python

import qarnot

conn = qarnot.connection.Connection(client_token="<<<MY_SECRET_TOKEN>>>")

task = conn.create_task('hello world from quay', 'docker-batch', 1)

task.constants['DOCKER_SRV'] ='https://quay.io'
task.constants['DOCKER_REPO'] = 'centos/centos'
task.constants['DOCKER_TAG'] = '8'
task.constants['DOCKER_CMD'] = 'echo hello world from Quay'

task.run()

print(task.stdout())

Bash

#!/bin/bash

qarnot task create \
--name "hello world from quay" \
--profile "docker-batch" \
--instance 1 \
--constants \
  "DOCKER_REPO=centos/centos" \
  "DOCKER_TAG=8" \
  "DOCKER_SERV=https://quay.io" \
  "DOCKER_CMD=echo hello world from Quay"

If your repository is private, you will also need to add the constants DOCKER_REGISTRY_LOGIN and DOCKER_REGISTRY_PASSWORD.

Related Articles

To start using docker images on Qarnot please read the following guides