title: Logstash can't connect to MySQL database
body: <p>I'm trying to synchronize the data between the MySQL database and an Elasticsearch using logstash.
  For that, I created a <code>docker-compose</code> file that creates containers for Elasticsearch, MySQL and Logstash.</p>
  <p>here is the file:</p>
  <h2>docker-compose.yml</h2>
  <pre><code>version: '3.1'
  
  services:
     elasticsearch:
       image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1
       container_name: pelasticsearch
       environment:
       - discovery.type=single-node
       - cluster.name=docker-cluster
       - bootstrap.memory_lock=true
       - &quot;ES_JAVA_OPTS=-Xms512m -Xmx512m&quot;
       ulimits:
         memlock:
           soft: -1
           hard: -1
       volumes:
       - elasticsearch:/home/django/elasticsearch
       ports:
       - 9200:9200
  
     db:
      image: mysql
      container_name: pmysqldb
      command: --default-authentication-plugin=mysql_native_password
      restart: always
      volumes:
        - ${PWD}/pdata/data:/docker-entrypoint-initdb.d
      environment:
        MYSQL_ROOT_PASSWORD: example
        MYSQL_DATABASE: ecommerce
  
     adminer:
      image: adminer
      restart: always
      ports:
        - 8080:8080
  
     logstash:
         image: docker.elastic.co/logstash/logstash:7.1.1
         links:
         - elasticsearch
         volumes:
         - ${PWD}/ls_config:/usr/share/logstash/config/
         command: bin/logstash-plugin install logstash-input-jdbc
         command: logstash -f /usr/share/logstash/config/logstash.conf
         depends_on:
         - elasticsearch
  
  volumes:
    elasticsearch:
  
  </code></pre>
  <p>I also had the <code>logstash.yml</code> and the <code>logstash.conf</code> files to configure my logstash plugin.</p>
  <h2>logstash.conf</h2>
  <pre><code>input {
    jdbc {
      jdbc_driver_library =&gt; &quot;./mysql-connector-java-5.1.36-bin.jar&quot;
      jdbc_driver_class =&gt; &quot;com.mysql.jdbc.Driver&quot;
      jdbc_connection_string =&gt; &quot;jdbc:mysql://localhost:3306/ecommerce&quot;
      jdbc_user =&gt; &quot;root&quot;
      jdbc_password =&gt; &quot;exmaple&quot;
      schedule =&gt; &quot;* * * * *&quot;
      statement =&gt; &quot;SELECT * from ecommerce.table;&quot;
    }
  }
  output {
     elasticsearch {
          hosts =&gt; [&quot;elasticsearch:9200&quot;]
          user =&gt; elastic
          password =&gt; changeme
     }
  }
  </code></pre>
  <h2>logstash.yml</h2>
  <pre><code>---
  http.host: '0.0.0.0'
  xpack.monitoring.elasticsearch.hosts: [ &quot;elasticsearch:9200&quot;]
  xpack.monitoring.elasticsearch.username: elastic
  xpack.monitoring.elasticsearch.password: changeme
  xpack.monitoring.enabled: true
  
  </code></pre>
  <p>So, when I run a <code>docker-compose up</code> all my containers are running including logstash, however when the logstash tries to run the conf file it seems to be unable to load the driver and returns an error as the following:</p>
  <pre><code>logstash_1       |   2056     LogStash::ConfigurationError
  logstash_1       |   2056     com.mysql.jdbc.Driver not loaded. Are you sure you've included the correct jdbc driver in :jdbc_driver_library?
  logstash_1       |   2056       /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-input-jdbc-4.3.13/lib/logstash/plugin_mixins/jdbc/jdbc.rb:163:in `open_jdbc_connection'
  </code></pre>
  <p>Since I'm new to both docker and logstash, is there anything I'm doing wrong? and how to solve this error.</p>