Build a Docker image in one job and use it in another job

Sometimes you may want to build a Docker image in one job, and use it in a downstream job. For small images, you can achieve that by using workspaces to share the data among jobs. 

Build job

  • Build the Docker image

  • Save the image to a tar file
    docker save -o <file path for generated tar file> <image name>
  • Use the persist_to_workspace key to make the file available to other jobs.

 

Downstream job(s)

  • Use the attach_workspace key to configure the job(s) to get the previously saved data

  • Load the Docker image from the workspace
    docker load -i <path to image tar file>

 

Note: If your images are large (>~1GB) this will probably not be a great solution. You can try to gzip the images as well or consider strategies to reduce your images size.

Was this article helpful?
11 out of 28 found this helpful

Comments

0 comments

Article is closed for comments.