Install plugins before COPY fluent.conf?
I'm using the 'onbuild' base image to create my custom fluentd image.
Dockerfile as below
ROM fluent/fluentd:v1.0.2-onbuild
RUN apk add --update --virtual .build-deps sudo build-base ruby-dev \
&& sudo gem install fluent-plugin-kubernetes_metadata_filter -v 1.0.0 -no-ri -no-rdoc \
&& sudo gem install fluent-plugin-prometheus -v 1.0.0 -no-ri -no-rdoc \
&& sudo gem install fluent-plugin-kinesis -v 2.1.0 -no-ri -no-rdoc \
&& sudo gem install fluent-plugin-kinesis-aggregation -v 0.3.0 -no-ri -no-rdoc \
&& sudo gem sources --clear-all \
&& apk del .build-deps \
&& rm -rf /var/cache/apk/* /home/fluent/.gem/ruby/2.3.0/cache/*.gem
EXPOSE 24231
However, everytime I update fluent.conf and rebuild, it will reinstall all plugins stated in the Dockerfile above. Had a look at the original Dockerfile and my understanding is that fluent.conf is copied BEFORE the plugin installs defined in my Dockerfile, which resulted in all docker build steps after the this step to be forced to re-run when fluent.conf is changed. Is there a way I can install plugins before copying the fluent.conf?
Thanks!
Had a look at the original Dockerfile and my understanding is that fluent.conf is copied BEFORE the plugin installs defined in my Dockerfile
So does moving installation step to before fluent.conf copy resolve this problem?
Yes, but as you can see, I have to install extra fluentd plugins in my Dockerfile, which always happens after the ONBUILD COPY fluent.conf step that happens in the fluent/fluentd:v1.0.2-onbuild image. And there doesn't seem to have a way for me to move my installation steps before that.
There a two possible way I can think of to fix this:
- In the onbuild image, copy a plugin dependency file (e.g. plugin-requirement.txt), which describes the name and version of all plugins needed, and "gem install" them in the onbuild image, before copying the fluent.conf.
- Don't include "ONBUILD COPY fluent.conf" in fluent's onbuild image (this will be a breaking change though)
Either way, it makes sure thta the fluent.conf is copied after the plugin install.