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"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:
DOCKER_CMD is certainly the most useful of all, as it is the one that allows you to parametrize the command that will be executed by the docker container.ENTRYPOINT is specified by the Dockerfile of the image used for your payload, it will be honored. E.g. with ENTRYPOINT ["echo", "Hello"]and DOCKER_CMD = " World" you will get Hello World on the console.DOCKER_REPO (repository name) and DOCKER_TAG (latest by default) allow you to choose the docker image that will be used. By default, the image is searched on Docker Hub.DOCKER_REGISTRY_LOGIN: Your login on the Docker Hub (if the image is in a private repository).DOCKER_REGISTRY_PASSWORD: Your password on the Docker Hub (if the image is in a private repository).DOCKER_SRV can be used to modify the address of the docker registry to be used (Docker Hub by default).DOCKER_SSH: lets you fill in your ssh public key in ssh-enabled profiles (see the advanced use-case accessing a task through ssh).
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"
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.
To start using docker images on Qarnot please read the following guides