TL;DL

前の記事の続き。boot2docker で Docker 1.8 の logging driver fluentd をほんの少し試した。

upgrade

% boot2docker upgrade

確認。

% docker version
Client:
 Version:      1.8.0
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   0d03096
 Built:        Tue Aug 11 17:17:40 UTC 2015
 OS/Arch:      darwin/amd64

Server:
 Version:      1.8.0
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   0d03096
 Built:        Tue Aug 11 17:17:40 UTC 2015
 OS/Arch:      linux/amd64

fluentd コンテナの用意

こちらを参考にさせて頂いて、以下のような Dockerfile を用意。

FROM kiyoto/fluentd:0.10.56-2.1.1
MAINTAINER inokappa
RUN mkdir /fluentd
ADD fluentd.conf /fluentd/
ENTRYPOINT ["/usr/local/bin/fluentd", "-c", "/fluentd/fluentd.conf"]

build する。

$ docker build -t inokappa/fluentd .

起動する。

docker run -d 
  --name=fluentd 
  -p 24224:24224 
inokappa/fluentd

アプリケーションコンテナの起動

以下のように fluentd コンテナの IP を指定して起動。

docker run 
  --log-driver=fluentd 
  --log-opt=fluentd-address=${FLUENTD_PORT_24224_TCP_ADDR}:24224 
  --log-opt=fluentd-tag=docker.{{.FullID}} 
  --name=foo 
hello-world

確認。

$ docker logs fluentd
2015-08-12 08:54:41 +0000 [info]: using configuration file: 
    type forward
    port 24224
    bind 0.0.0.0
  
    type stdout
  
2015-08-12 08:54:41 +0000 [info]: adding source type="forward"
2015-08-12 08:54:41 +0000 [info]: adding match pattern="docker.**" type="stdout"
2015-08-12 08:54:41 +0000 [info]: listening fluent socket on 0.0.0.0:24224
2015-08-12 08:55:06 +0000 docker.bcc734640cf824e007e66b324eaf55fb9cd63f6d5439b45f6446d1b978f2b7e6: {"container_name":"/foo","source":"stdout","log":"","container_id":"bcc734640cf824e007e66b324eaf55fb9cd63f6d5439b45f6446d1b978f2b7e6"}

(snip)

2015-08-12 08:55:06 +0000 docker.bcc734640cf824e007e66b324eaf55fb9cd63f6d5439b45f6446d1b978f2b7e6: {"container_id":"bcc734640cf824e007e66b324eaf55fb9cd63f6d5439b45f6446d1b978f2b7e6","container_name":"/foo","source":"stdout","log":"For more examples and ideas, visit:"}
2015-08-12 08:55:06 +0000 docker.bcc734640cf824e007e66b324eaf55fb9cd63f6d5439b45f6446d1b978f2b7e6: {"container_id":"bcc734640cf824e007e66b324eaf55fb9cd63f6d5439b45f6446d1b978f2b7e6","container_name":"/foo","source":"stdout","log":" https://docs.docker.com/userguide/"}
2015-08-12 08:55:06 +0000 docker.bcc734640cf824e007e66b324eaf55fb9cd63f6d5439b45f6446d1b978f2b7e6: {"container_id":"bcc734640cf824e007e66b324eaf55fb9cd63f6d5439b45f6446d1b978f2b7e6","container_name":"/foo","source":"stdout","log":""}

アプリケーションコンテナ(2)

コンテナ起動。

docker run -d 
  --log-driver=fluentd 
  --log-opt=fluentd-address=${FLUENTD_PORT_24224_TCP_ADDR}:24224 
  --log-opt=fluentd-tag="docker.{{.Name}}" 
  --name=web-01 
  --hostname=web-01 
  -p 8000:8000 
inokappa/centos-base /bin/sh -c 'cd /tmp/ && hostname -s > index.html && python -m SimpleHTTPServer'

確認。

% curl ${DOCKER_HOST}:8000
web-01
% curl ${DOCKER_HOST}:8000
web-01
% curl ${DOCKER_HOST}:8000
web-01

ログ確認。

$ docker logs fluentd

(snip)

2015-08-12 09:02:58 +0000 docker./web-01: {"source":"stderr","log":"192.168.59.3 - - [12/Aug/2015 09:02:58] "GET / HTTP/1.1" 200 -","container_id":"465b74a8542093e094393e433154d4490ed15ff542c6942b02d14a70f637362d","container_name":"/web-01"}
2015-08-12 09:03:02 +0000 docker./web-01: {"container_id":"465b74a8542093e094393e433154d4490ed15ff542c6942b02d14a70f637362d","container_name":"/web-01","source":"stderr","log":"192.168.59.3 - - [12/Aug/2015 09:03:02] "GET / HTTP/1.1" 200 -"}
2015-08-12 09:03:03 +0000 docker./web-01: {"container_id":"465b74a8542093e094393e433154d4490ed15ff542c6942b02d14a70f637362d","container_name":"/web-01","source":"stderr","log":"192.168.59.3 - - [12/Aug/2015 09:03:03] "GET / HTTP/1.1" 200 -"}

以上。

元記事はこちら

Docker の Logging driver に fluentd が組み込まれるということでリリースを待ちきれずに試してみたメモ(boot2docker 版)