Logstash container crashes with weird error

Hello,

I am trying to make an integration between Elasticsearch and SQL Server via Logstash.
I have created my dockerfile for that integration where base image is logstash.
First the error I am getting is:

elasticsqlserver_1 | ERROR: Unknown command '/bin/sh'
elasticsqlserver_1 |
elasticsqlserver_1 | See: 'bin/logstash --help'
elasticsqlserver_1 | [ERROR] 2019-03-06 11:35:55.237 [main] Logstash - java.lang.IllegalStateException: Logstash stopped processing because of an error: (SystemExit) exit
elasticsqlserver_1 exited with code 1

When I run clean logstash container, with whoami I can see I am working as a logstash user and I can enter /bin/sh without problems.

My dockerfile looks like:

FROM logstash:6.5.0

#switch to root user

USER root

#arguments

ARG dbHost=foo

ARG dbName=foo

ARG dbUser=foo

ARG dbUserPassword=foo

ARG elasticHost=www.google.com

ARG dbTable=foo

ARG elasticIndex=foo

ARG shardNum=foo

ARG replicasNum=foo

#host where database is located

ENV dbHost ${dbHost}

#database name

ENV dbName ${dbName}

#database user

ENV dbUser ${dbUser}

#database user password

ENV dbUserPassword ${dbUserPassword}

#host where Elasticsearch is located

ENV elasticHost $elasticHost

#table to log

ENV dbTable ${dbTable}

#index name

ENV elasticIndex ${elasticIndex}

#number of shards

ENV shardNum ${shardNum}

#number of replicas

ENV replicasNum ${replicasNum}

RUN usermod -a -G root logstash

#copying jar for sql server into /bin/jdbc directorys

COPY ./sqljdbc42.jar /bin/jdbc/

#adding system variable CLASSPATH for sqljdbc

RUN echo 'export CLASSPATH="/bin/jdbc/sqljdbc42.jar"' >> /root/.bashrc

#creating Elasticsearch index for SQL Server logs

RUN echo $(curl -XPUT --silent '${elasticHost}/${elasticIndex}' -d '{"settings" : {"index" : {"number_of_shards" : ${shardNum}, "number_of_replicas" : ${replicasNum}}}}')

#setting working directory

WORKDIR /bin/jdbc

#configuring LogStash configuration file

RUN echo "input {" >> sql.conf

RUN echo " jdbc {" >> sql.conf

RUN echo " jdbc_connection_string => "jdbc:sqlserver://${dbHost};databaseName=${dbName};db_username=${dbUser};db_password=${dbUserPassword}"" >> sql.conf

RUN echo " jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"" >> sql.conf

RUN echo " jdbc_user => ${dbUser}" >> sql.conf

RUN echo "" >> sql.conf

RUN echo " statement => "select * from $dbTable"" >> sql.conf

RUN echo " }" >> sql.conf

RUN echo "}" >> sql.conf

RUN echo "" >> sql.conf

RUN echo "output {" >> sql.conf

RUN echo " elasticsearch {" >> sql.conf

RUN echo " hosts => ["${elasticHost}"]" >> sql.conf

RUN echo " index => "${elasticIndex}"" >> sql.conf

RUN echo " }" >> sql.conf

RUN echo "}" >> sql.conf

RUN chown --recursive logstash /usr/share/logstash/bin/logstash

# USER logstash

ENTRYPOINT ["/usr/share/logstash/bin/logstash", "-f", "/bin/jdbc/sql.conf", "-l", "logstash.log"]

When I run this my container stays alive for around 30 seconds and just drop dead. I got above error with docker logs. This is as far as I can get cause I can't enter container for more debugging cause that container can't stay alive.

I don't know if that is some bug in logstash image or is this something from my side cause error message is way abstract and can't read anything useful from it.

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