[[log-driver-usage-examples]]
== {log-driver} usage examples

++++
<titleabbrev>Usage examples</titleabbrev>
++++


The following examples show common configurations for the {log-driver}.

[float]
=== Send Docker logs to {es} 

*Docker run command:*

["source","sh",subs="attributes"]
----
docker run --log-driver=elastic/{log-driver-alias}:{version} \
           --log-opt hosts="myhost:9200" \
           --log-opt user="myusername" \
           --log-opt password="mypassword" \
           -it debian:jessie /bin/bash
----

*Daemon configuration:*

["source","json",subs="attributes"]
----
{
  "log-driver" : "elastic/{log-driver-alias}:{version}",
  "log-opts" : {
    "hosts" : "myhost:9200",
    "user" : "myusername",
    "password" : "mypassword",
  }
}
----

[float]
=== Send Docker logs to {ess} on {ecloud}

*Docker run command:*

["source","sh",subs="attributes"]
----
docker run --log-driver=elastic/{log-driver-alias}:{version} \
           --log-opt cloud_id="MyElasticStack:daMbY2VudHJhbDekZ2NwLmN4b3VkLmVzLmliJDVkYmQwtGJiYjs0NTRiN4Q5ODJmNGUwm1IxZmFkNjM5JDFiNjdkMDE4MTgxMTQzNTM5ZGFiYWJjZmY0OWIyYWE5" \
           --log-opt cloud_auth="myusername:mypassword" \
           -it debian:jessie /bin/bash
----

*Daemon configuration:*

["source","json",subs="attributes"]
----
{
  "log-driver" : "elastic/{log-driver-alias}:{version}",
  "log-opts" : {
    "cloud_id" : "MyElasticStack:daMbY2VudHJhbDekZ2NwLmN4b3VkLmVzLmliJDVkYmQwtGJiYjs0NTRiN4Q5ODJmNGUwm1IxZmFkNjM5JDFiNjdkMDE4MTgxMTQzNTM5ZGFiYWJjZmY0OWIyYWE5",
    "cloud_auth" : "myusername:mypassword",
    "output.elasticsearch.index" : "elastic-log-driver-%{+yyyy.MM.dd}"
  }
}
----

[float]
=== Specify a custom index and template

*Docker run command:*

["source","sh",subs="attributes"]
----
docker run --log-driver=elastic/{log-driver-alias}:{version} \
           --log-opt hosts="myhost:9200" \
           --log-opt user="myusername" \
           --log-opt password="mypassword" \
           --log-opt index="eld-%{[agent.version]}-%{+yyyy.MM.dd}" \
           -it debian:jessie /bin/bash
----

*Daemon configuration:*

["source","json",subs="attributes"]
----
{
  "log-driver" : "elastic/{log-driver-alias}:{version}",
  "log-opts" : {
    "hosts" : "myhost:9200",
    "user" : "myusername",
    "index" : "eld-%{[agent.version]}-%{+yyyy.MM.dd}",
    "password" : "mypassword",
  }
}
----
