Tuesday, August 25, 2015

Docker 1.8 with td-agent 2.2.1 container

This is a quick guide on setting up td-agent container with Docker 1.8

  1. Create a directory to store your dockerfile and td-agent config file. 
  2. mkdir ~/td-agent-es && cd ~/td-agent-es
    
  3. Create a dockerfile as shown below
  4. Create td-agent.conf file as shown below
  5. Build the docker image
  6. docker build -t td-agent-es .
    
  7. Start elasticsearch container. As you can see from the td-agent.conf, the td-agent container will link to this elasticsearch container. Please note that this setup is not using any persistent storage mapping. You can refer to this link for more information on how to setup that mapping.
  8. docker run -d -p 9200:9200 -p 9300:9300 --name es elasticsearch
    
  9. Start your td-agent container 
  10. docker run -d -p 24224:24224 --link es:es --name td-agent td-agent-es
    
  11. Launch a hello-world to see if td-agent is forwarding log to elasticsearch container. Please note that Docker 1.8 add fluentd as one of the logging-driver. So this command will not work if you are using Docker with older version
  12. docker run --log-driver=fluentd --log-opt fluentd-address=[your-host-IP-address]:24224 hello-world
  13. Use the following command to check if elasticsearch container is receiving log. You can check container ID or container name using docker ps -a
  14. curl -XGET 'http://[your-host-IP-address]:9200/_all/_search?q=*'
    

No comments: