"docker-compose build" is not caching layers?

Building - or trying to - a docker image for an MQTT Integration , which will allow Energenie RF devices (sockets, TRVs, etc) to be controlled with the standard HA MQTT Integration.

Part of this build relies on building specific builds of log4c and mosquitto from src. I’ve got the build working but when I run docker-compose after a successful build, it appears to run the whole build and not caching layers. I thought each RUN command in the Dockerfile created a layer and if one does not change preceding statements then each of these layers is cached?

I’ve posted a few dev questions on the forum but no reply to them thus far; this is HA work so …???

Anyway, do we have a dev who uses Docker to build images , might be able to point me in the right direction please?


FROM gcc:8.3.0
COPY . /usr/src/log4c
WORKDIR /usr/src/log4c
RUN echo "!!-- PATH=${PATH}"
RUN sh -c './01_download.sh'
RUN sh -c 'gzip -dcv log4c-1.2.4.tar.gz | tar xvf -'
RUN sh -c 'cd ./log4c-1.2.4 ; ./configure && make && make install'
RUN echo "!!-- SUCCESS , BUILT log4c"
CMD ["/bin/sh" , "-c" , "echo THIS IS RUNNING CONTAINER FOR log4c LIB"]

docker-compose build successfully builds the image, and I can run it. If I run the same command again , then the entire build is performed even though I haven’t changed the Dockerfile. ??

…and here’s the history of the layers , all looks good to me ?

daz@LianLiPC-7NB:/mnt/c/Users/daz/DEV/Energenie/log4c$ docker history energenie_log4c
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
888e92a6710e        16 minutes ago      /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "echo…   0B              
06604b703440        16 minutes ago      /bin/sh -c echo "!!-- SUCCESS , BUILT log4c"    0B              
464c7bcd40a7        16 minutes ago      /bin/sh -c sh -c 'cd ./log4c-1.2.4 ; ./confi…   4.99MB          
ff0b699484bd        17 minutes ago      /bin/sh -c sh -c 'gzip -dcv log4c-1.2.4.tar.…   2.35MB          
2d4e3746d99b        17 minutes ago      /bin/sh -c sh -c './01_download.sh'             0B              
ef5d40fc01a7        17 minutes ago      /bin/sh -c echo "!!-- PATH=${PATH}"             0B              
095f36056ef8        17 minutes ago      /bin/sh -c #(nop) WORKDIR /usr/src/log4c        0B              
2261f4fe7db7        17 minutes ago      /bin/sh -c #(nop) COPY dir:b4b38b590c52aa0bd…   560kB


Schoolboy error; forgot to use the –tag energenie_log4c:1.0
All working now and caching :+1:
too late, need zzzzzz

so for anyone coming across this via a forum search, the answer is to use image and container_name , and the key is to tag the version , in my case :1.0 rather than the default latest which rebuilds every time…:

version: '3'
    image: energenie_log4c:1.0
    container_name: energenie-log4c
    build: ./log4c
    working_dir: /usr/src/log4c
    network_mode: host
    command: sh -c 'echo "!!-- BUILD COMPLETE"'

While I have no idea what you are talking about, someone here will https://discord.gg/bju9vV

EDIT: you got it working. Still might be worthwhile joining that discord.

1 Like

Thanks mate. Didn’t realise HA was on discord. :+1: