Install dependencies in the docker container

I'm new to docker and I'm struggling a bit with installing the required prerequisites.
I have this in my docker-composer.yml file, because I need the sflow plugin and I need the mysql jdbc driver:

command: >
  bash -c "export http_proxy='http://proxy:3128' &&
           export https_proxy=$http_proxy &&
           export JRUBY_OPTS='-J-Dhttp.proxyHost=proxy -J-Dhttp.proxyPort=3128' &&
           DEBUG=1 JARS_SKIP='true' &&
           bin/logstash-plugin install logstash-codec-sflow &&
           yum install -y mysql-connector-java &&
           bin/logstash"
user: root

This looks extremely unelegant to me as it is executed every time I run docker-compose up.

Is there no way to install the required dependencies just once and persist them? If I drop into an interactive shell, install what's needed, then everything is gone when I run docker-compose down.

I'm pretty new to Docker too, but I understand one way to do this is by creating a docker image. Basically you build the image (based on a specific 'logstash' dockerfile) and do the plugin install etc as part of that script. Once this is done you reference the image from your compose setup.

e.g. in docker file do something like this ..

COPY ./plugins/logstash-filter-myfilter-0.0.1.gem /usr/share/logstash/plugins/logstash-filter-myfilter-0.0.1.gem

RUN /usr/share/logstash/bin/logstash-plugin install --no-verify --local /usr/share/logstash/plugins/logstash-filter-myfilter-0.0.1.gem

build the image

docker build -f logstash.Dockerfile -t myimage .

and then in your compose yml file

logstash:
image: myimage

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.