# Cannot cache docker builds on 1.9.1+

**URL:** <https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781>\
**Category:** Build Environment\
**Created:** [June 23, 2016, 7:14pm UTC](https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781 "2016-06-23T19:14:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarikjn](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/tarikjn/32/13338_2.png) [@tarikjn](https://discuss.circleci.com/u/tarikjn)\
**Post date:** [June 23, 2016, 7:14pm UTC](https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781/1 "2016-06-23T19:14:11Z")

</div>

Hi there, we are evaluating using CircleCI for our flagship web product builds, but are having some issues caching docker builds. We use docker build’s build-args argument to pass an SSH key down to the container which means we can only use docker 1.9.1+.

However the solution proposed on the CircleCI doc fails on 1.9.1 because docker save gives the following error:  
mkdir -p ~/docker; docker save $IMAGE\_NAME \> ~/docker/image.tar  
Error response from daemon: chtimes /var/lib/docker/tmp/docker-export-185042988/47ed1778199d0fade4926082ad19a1891e3ed967c65cca90642842e158054342: invalid argument  
It seems related to this issue: docker/issues/20324

On 1.10 no failure, but cache is not working because of this other docker issue: docker/issues/20380

I then went onto a second strategy which is to use docker pull and actually sounds better as recommended on: [https://karthikv.net/articles/circleci-docker-flow/](https://karthikv.net/articles/circleci-docker-flow/), however this will not work on 1.10 because of the content-addressable storage changes, see: docker/issues/20316

Last option is to use docker 1.9.1 with pull caching, but it does not seem to use the cache when building, we pull our image from a private registry, so could it be related to this issue: [https://groups.google.com/forum/#!topic/docker-user/Wki9c9Qcu-E](https://groups.google.com/forum/#!topic/docker-user/Wki9c9Qcu-E)

I would appreciate any pointer as I spent quite a while trying to get this to work. Sorry that I had to cut github links, this support forum would otherwise give me this error: “Sorry, new users can only put 2 links in a post.”

---

<div class="post-metadata">

**Author:** ![levlaz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/levlaz/32/36978_2.png) [@levlaz](https://discuss.circleci.com/u/levlaz)\
**Post date:** [June 25, 2016, 1:22am UTC](https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781/2 "2016-06-25T01:22:23Z")

</div>

Sadly there is no great support for Docker caching at the moment. Please check out [this doc](https://circleci.com/docs/docker/#caching-docker-layers) for more information.

---

<div class="post-metadata">

**Author:** ![rasmuslp](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rasmuslp/32/13738_2.png) [@rasmuslp](https://discuss.circleci.com/u/rasmuslp)\
**Post date:** [August 24, 2016, 11:25am UTC](https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781/3 "2016-08-24T11:25:54Z")

</div>

I have followed the example of saving/loading from the doc, but I can only get this to work on Ubuntu 12.04 with Docker 1.8.

On Ubuntu 14.04 with Docker 1.9, it always seems to ignore the cache when building the image.

Are there _any_ way of running Docker 1.9+ with local caching (i.e. no remote repository) at the moment?

Yaml for context:

```auto
machine:
  services:
    - docker

dependencies:
  cache_directories:
    - "~/docker"

  override:
    - docker info
    - if [[-e ~/docker/image.tar]]; then docker load -i ~/docker/image.tar; fi
    - docker build -t $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME .
    - mkdir -p ~/docker; docker save $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME > ~/docker/image.tar

...

```

---

<div class="post-metadata">

**Author:** ![john2x](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/john2x/32/640_2.png) [@john2x](https://discuss.circleci.com/u/john2x)\
**Post date:** [October 13, 2016, 11:16am UTC](https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781/4 "2016-10-13T11:16:35Z")

</div>

I’m following the same snippet on 14.04 environment and caching also doesn’t work. The image is loaded (I added a `docker images` command to my circle.yml) but the `docker build` command still builds from scratch.

---

<div class="post-metadata">

**Author:** ![jspiro](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jspiro/32/13896_2.png) [@jspiro](https://discuss.circleci.com/u/jspiro)\
**Post date:** [October 21, 2016, 2:25am UTC](https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781/5 "2016-10-21T02:25:26Z")

</div>

Likewise. Ironically, when I ssh into the box and rebuild the image, it uses the cache (presumably from the build having just run, not the load).

Of course, we can’t remove images, so there’s no way for me to test it interactively in ssh.

This is most of my build time. I can’t imagine they’d prefer to download a gig every single build versus caching that same gig.

---

<div class="post-metadata">

**Author:** ![olalonde](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/olalonde/32/16099_2.png) [@olalonde](https://discuss.circleci.com/u/olalonde)\
**Post date:** [October 21, 2016, 7:40pm UTC](https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781/6 "2016-10-21T19:40:17Z")

</div>

Also having this problem. I followed the trick outlined at [https://circleci.com/docs/docker/#caching-docker-layers](https://circleci.com/docs/docker/#caching-docker-layers) but it doesn’t work. The image is correctly cached in ~/docker and subsequent builds can `ls` the image but for some reason, docker doesn’t use the cached layers.

Here’s my circle.yml:

```auto
machine:
  services:
    - docker

dependencies:
  cache_directories:
    - "~/docker"
  override:
    - make docker-load
    - make build
    - make docker-save

database:
  override:
    - echo "Override CircleCI auto-detected databases"

test:
  # see https://discuss.circleci.com/t/docker-run-error-bind-address-already-in-use/294/10
  pre:
    - sudo service postgresql stop
    - $(aws ecr get-login --region us-west-1)
  override:
    - npm run docker:test

```

And bits of my Makefile:

```
# hack to get caching in circleci
docker-load:
	ls ~/docker || true
	[[-e ~/docker/image.tar]] && docker load -i ~/docker/image.tar || true
.PHONY: docker-save
docker-save:
	mkdir -p ~/docker
	docker save ${IMAGE} > ~/docker/image.tar
	ls ~/docker || true
.PHONY: docker-build
docker-build:
	docker build --pull \
		--rm=false \
		--build-arg NPM_TOKEN=${NPM_TOKEN} \
		-t ${IMAGE} .
	docker tag ${IMAGE} ${SHORT_NAME}:test
```

---

<div class="post-metadata">

**Author:** ![bilby91](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/bilby91/32/14673_2.png) [@bilby91](https://discuss.circleci.com/u/bilby91)\
**Post date:** [November 25, 2016, 6:01am UTC](https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781/7 "2016-11-25T06:01:10Z")

</div>

Having the same problem here. Image seems to be loading correctly but docker ignores the cache.

---

<div class="post-metadata">

**Author:** ![alec](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@alec](https://discuss.circleci.com/u/alec)\
**Post date:** [January 13, 2017, 1:03am UTC](https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781/8 "2017-01-13T01:03:52Z")

</div>

This needs to get its own post. Having this issue as well.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:38am UTC](https://discuss.circleci.com/t/cannot-cache-docker-builds-on-1-9-1/4781/9 "2018-06-18T11:38:27Z")

</div>

Closed on June 18, 2018, 11:38am UTC


