Deploy a job from pre-built image


What you'll learn

  • Creating a Docker file for our training code.
  • Push the Dockerfile to a Docker registry.
  • Deploying our Docker Image as a job via servicefoundry.

This is a guide to deploy training code as a job from a pre-built image stored in an external registry.

For this guide we will use the public registry. However, if you wish you can integrate your registry with Truefoundry.

After you complete the guide, you will have a successful deployed job. Your jobs deployment dashboard will look like this:

Project structure

To complete this guide, you are going to create the following files:

  • : contains our training code
  • Dockerfile: contains our docker image build instructions
  • contains our deployment code / deployment configuration. (Depending on whether you choose to use our python SDK or create a YAML file)
  • requirements.txt : contains our dependencies.

Your final file structure is going to look like this:-

├── Dockerfile
├── / deploy.yaml
└── requirements.txt

As you can see, all the following files are created in the same folder/directory.

Step 1: Implement the training code

The first step is to create a job that trains a scikit learn model on iris dataset

We start with a requirements.txt with our dependencies and a containing our training code.

└── requirements.txt



# for deploying our job deployments

This file fetches the data and trains the model.

Step 3: Dockerize the training code

Now we will create the Dockerfile for the training code.

├── Dockerfile
└── requirements.txt


The Dockerfile contains instructions to build the image.

Step 4: Build the image, tag it, push it

To push to sign up and replace your username below.

docker login  # This will prompt for credentials
docker build . -t <YOUR_DOCKERHUB_USERNAME>/tf-job-docker-image:latest
docker push <YOUR_DOCKERHUB_USERNAME>/tf-job-docker-image:latest

This will build the image locally and push it to Once done, <YOUR_DOCKERHUB_USERNAME>/tf-job-docker-image:latest will be the Image URI that we can reference.

Step 5: Deploying as a job from image

You can deploy services on TrueFoundry programmatically either using our Python SDK, or via a YAML file.

So now you can choose between either creating a file, which will use our Python SDK.
Or you can choose to create a deploy.yaml configuration file and then use the servicefoundry deploy command

Via python SDK

File Structure

└── requirements.txt

Follow the recipe below to understand the file :-

To deploy the job using Python API use:


Via YAML file

File Structure

├── deploy.yaml
└── requirements.txt

Follow the recipe below to understand the deploy.yaml file :-

To deploy the job using Python API use:

servicefoundry deploy --workspace-fqn YOUR_WORKSPACE_FQN --file deploy.yaml

Run the above command from the same directory containing the and requirements.txt files.


.tfyignore files

If there are any files you don't want to be copied to the workspace, like a data file, or any redundant files. You can use .tfyignore files in that case.

End result

On successful deployment, the Job will be created and run immediately.

We can now visit our Applications page to check Build status, Build Logs, Runs History and monitor progress of runs.
See Monitoring and Debugging guide for more details.

See Also