gpbenton / engMQTTClient

MQTT client for Energenie ener314-rt board running on a raspberry Pi
MIT License
21 stars 10 forks source link

Use a multi stage build to make the docker image smaller #27

Closed gpbenton closed 3 years ago

DrHoneyBear commented 3 years ago

No description provided. Graham, I can for sure mod my Docker file to use Multi Stage Build. However, the reality is:

  • There are four phases of the current build.
  • Phase 1 is log4c build from sources. This could be reduced down by removing sources after build.
  • Phase 2 is mosquito package install. This cannot be reduced down.
  • Phase 3 is your engmqtt client/broker. This could be reduced down by removing sources after build.
  • Phase 4 executable.
  • The removal of log4c and your engmqtt sources is not going to make any noticeable difference to the net resultant image.

The Dockerfile already is multi-stage, it utilises the FROM and RUN directives. A dev environment using gcc is created as an intermediate image. The final image for RUN contains this env and the sources. What could be applied in order to reduce image size, is to remove this build image from the final image, viz:-

Is this what you mean?

gpbenton commented 3 years ago

That is exactly what I mean. It should be straightforward, I just haven't had a free weekend to try it out.

gpbenton commented 3 years ago

New image released as gpbenton/engmqttclient:2.0.0. 81.6MB as opposed to 872MB. Added some example to the docker-compose on how to add debug.