9

I'm configuring a bamboo build plan to build docker images. Using AWS ECS as registry. Build plan is something like this;

  • pull the latest tag

    docker pull xxx.dkr.ecr.eu-west-1.amazonaws.com/myimage:latest
    
  • build image with latest tag

    docker build -t myimage:latest .
    
  • tag the image (necessary for ECS)

    docker tag -f myimage:latest xxx.dkr.ecr.eu-west-1.amazonaws.com/myimage:latest
    
  • Push the image to the registry

    docker push xx.dkr.ecr.eu-west-1.amazonaws.com/myimage:latest
    

Because build tasks run on different and fresh build engines/servers every time, It doesn't have local cache.

When I don't change anything at Dockerfile and execute it again(at another server), I would expect docker to use local cache(comes from docker pull) and doesn't execute each line again. But it tries to build image everytime. I was also expecting that when I change something at the bottom of the file, it's going to use cache and executes only the latest line, but I'm not sure about this.

Do I know something wrong or are there any opinions on approach?

code_ada
  • 874
  • 12
  • 25
  • Can you share some output of what "tries to build image everytime" looks like? You will still see each layer get "built" but it will say it's using the cache. – danehammer Dec 07 '17 at 15:41
  • 1
    08-Dec-2017 08:38:16 Step 8 : RUN add-apt-repository ppa:maxmind/ppa -y 08-Dec-2017 08:38:17 ---> Running in 5806bde2c3d3 08-Dec-2017 08:38:17 gpg: keyring `/tmp/tmp5o6q7_ge/secring.gpg' created 08-Dec-2017 08:38:17 gpg: keyring `/tmp/tmp5o6q7_ge/pubring.gpg' created 08-Dec-2017 08:38:17 gpg: requesting key DE742AFA from hkp server keyserver.ubuntu.com 08-Dec-2017 08:38:17 gpg: /tmp/tmp5o6q7_ge/trustdb.gpg: trustdb created 08-Dec-2017 08:38:17 gpg: key DE742AFA: public key "Launchpad PPA for MaxMind" imported 08-Dec – code_ada Dec 08 '17 at 08:55
  • just an example. as I said it doesn’t use previous layers. – code_ada Dec 08 '17 at 08:56
  • Can you try `docker build -t myimage:latest --cache-from xxx.dkr.ecr.eu-west-1.amazonaws.com/myimage:latest .`, see if it helps – Tarun Lalwani Dec 12 '17 at 17:18
  • still the same `Step 2/37 : RUN apt-get update ---> Running in 75f813c63132 Get:1 http://security.ubuntu.com trusty-security InRelease [65.9 kB]` – code_ada Dec 12 '17 at 22:18
  • Hey Have you tried this? docker build -t myimage:latest . - - no-cache – mohit Dec 13 '17 at 20:17
  • You might be hitting this: https://github.com/moby/moby/issues/31613 – tne Dec 17 '17 at 01:49

1 Answers1

4

are you considering using squid proxy ?

edit : in case you dont want to go to the official website above, here is quick setup on squid proxy (debian based)

apt-get install squid-deb-proxy

and then change the squid configuration to create a larger space by open up

/etc/squid/squid.conf

and replace #cache_dir ufs /var/spool/squid with cache_dir ufs /var/spool/ squid 10000 16 256 and there you go,, a 10.000 MB worth of cache space

and then point the proxy address in dockerfile,, here is a example of dockerfile with squid proxy

yum and apt-get based distro:

apt-get based distro

`FROM debian
RUN apt-get update -y && apt-get install net-tools
RUN echo "Acquire::http::Proxy \"http://$( \
route -n | awk '/^0.0.0.0/ {print $2}' \
):8000\";" \ > /etc/apt/apt.conf.d/30proxy
RUN echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> \
/etc/apt/apt.conf.d/30proxy
CMD ["/bin/bash"]`

yum based distro

`FROM centos:centos7
RUN yum update -y && yum install -y net-tools
RUN echo "proxy=http://$(route -n | \
awk '/^0.0.0.0/ {print $2}'):3128" >> /etc/yum.conf
RUN sed -i 's/^mirrorlist/#mirrorlist/' \
/etc/yum.repos.d/CentOS-Base.repo
RUN sed -i 's/^#baseurl/baseurl/' \
/etc/yum.repos.d/CentOS-Base.repo
RUN rm -f /etc/yum/pluginconf.d/fastestmirror.conf
RUN yum update -y
CMD ["/bin/bash"]`

lets say you install squid proxy in your aws registry,,only the first build would fetch the data from the internet the rest (another server) build should be from the squid proxy cached. .

this technique based on book docker in practice technique 57 with tittle set up a package cache for faster build

i dont think there is a cache feature in docker without any third party software.. maybe there is and i just dont know it. .im not sure,, just correct me if im wrong. .

Fendi jatmiko
  • 2,567
  • 1
  • 9
  • 15
  • 1
    the question is not about caching apt packages but image layers. – code_ada Dec 21 '17 at 09:54
  • well. .thats just my little example,, you could use squid cache on image layers too. . here's some example [docker caching proxy](http://planet.jboss.org/post/deploy_and_configure_a_local_docker_caching_proxy) – Fendi jatmiko Dec 21 '17 at 16:33