Use Bind-Mounted Setting for Local Config File?

Hello Logstash Wizards,

I’m struggling to understand how I can spin up a Logstash Docker container using bind-mounted settings (see here) to run the container with a config file on the local host.

To explain: Let’s say I have this Logstash config file ( /home/me/myconfig.conf ) on my Ubuntu server:

input{
  ...stuff...
}

filter{
  ...more stuff...
}

output{
  ...still more stuff...
}

I want to force the Logstash Docker container to run this config file when it spins up. So I create a custom logstash.yml file ( /home/me/logstash.yml ):

http.host: 0.0.0.0
path.config: /usr/share/logstash/config/myconfig.conf

And I set ownership and permissions on these files like this:

root@ubuntuhost:/home/me# ls -l
total 32
-rwxrwxrwx 1 logstash root 81 Jun 23 21:05 logstash.yml
-rwxrwxrwx 1 logstash root 28 Jun 12 19:16 myconfig.conf
root@ubuntuhost:/home/me#

A little overkill, but I don’t want any problems with the container being unable to access the files.

Now all I have to do is spin up the container, and make sure it understands where to find these two files on my host system:

docker run -it -d \
-v /home/me/logstash.yml:/usr/share/logstash/config/logstash.yml \
-v /home/me/myconfig.conf:/usr/share/logstash/config/myconfig.conf \
logstash:latest

What I’ve determined from trial-and-error is that the container can successfully access and read the logstash.yml file, but cannot access the myconfig.conf file. So I must be doing something wrong with that binding. I thought that this part of the spin-up command…

-v /home/me/myconfig.conf:/usr/share/logstash/config/myconfig.conf \

…essentially created a logical link within the container to my local file. Can anyone see what I’m doing wrong? Thanks, -RAO

could this be the issue ?

Thanks ptamba,

No, I'm afraid that isn't the solution. When I apply the ":ro" ("Read Only") at the end of the filename, it actually generates an error:

2020/06/25 20:47:37 Setting 'xpack.monitoring.elasticsearch.hosts' from environment.
2020/06/25 20:47:37 error: open /usr/share/logstash/config/logstash.yml: read-only file system

And when I drop the ":ro", it generates a massive Java error. Perhaps a bug in this version? (7.7.1)

I've been Googling for a while today; there doesn't seem to be an example of spinning up a LS Docker Container while bind-mounting the local config file.

i was referring to the config files. logstash in docker will look for the config in /usr/share/logstash/pipeline . your config uses /usr/share/logstash/config

have you tried this instead?

-v /home/me/myconfig.conf:/usr/share/logstash/pipeline/logstash.conf \
logstash:latest

...interesting! Yes, I will try over the weekend. Thanks, I'll let you know how it goes!

Yes, this worked, thank you!

A word of warning to anyone who might be following in my footsteps... You have to make sure to set permissions on the local files for this to work.