Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get --cache-from to work

I'm following the instructions at https://cloud.google.com/container-builder/docs/speeding-up-builds#using_a_cached_docker_image and I'm trying to setup docker builds that use the image cached from the previous build.

Here's what my cloudbuild.yml looks like:

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['pull', 'gcr.io/$PROJECT_ID/$REPO_NAME:infra_docker']
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '--cache-from', 'gcr.io/$PROJECT_ID/$REPO_NAME:infra_docker', '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:infra_docker', '.']
timeout: 120m
images: ['gcr.io/$PROJECT_ID/$REPO_NAME:infra_docker']
options:
  machineType: 'N1_HIGHCPU_8'

Here's what my Dockerfile starts with:

FROM ubuntu:14.04
SHELL ["/bin/bash", "-c"]
# lots of RUN commands after this

No matter what I try, the docker image pulled from the cache (as a result of the first step), is not used to speed up the actual docker build (second step). It always runs the entire 38 steps in my Dockerfile!

What am I doing wrong?

like image 992
Saurabh Nanda Avatar asked Feb 20 '18 09:02

Saurabh Nanda


1 Answers

Is the dockerfile multi-stage? I ran into this problem where only the final image is available for caching. Depending on the steps you run, this can appear as if no step is using the cache. If this is the case you need to push the intermediate image(s) to the container registry as well and pull them when building.

like image 61
Matt Avatar answered Oct 06 '22 20:10

Matt