DockerのFluentdにfluent-plugin-s3パッケージをインストール

IT技術

はじめに

Dockerで構築したFluentdからAWS S3にログ転送するため、fluent-plugin-s3パッケージをインストールする。

システム環境

  • OS:Oracle Linux Server 7.9
  • Docker Engine:19.03.11-ol
  • docker-compose:1.29.2

設定ファイル

ディレクトリ構成

<任意のディレクトリ>
L docker-compose.yml
L fluentd
 L Dockerfile
 L fluentd.conf

Dockerfile

FROM fluentd:v1.14-1
COPY fluentd.conf /fluentd/etc/fluentd.conf
USER root
RUN gem install fluent-plugin-s3
USER fluent

※「USER root」オプションについて
「USER root」オプションを付けないと、後述のDockerコンテナ起動時(build)に以下の権限不足エラーになったので注意。

Step 3/3 : RUN gem install 
 ---> Running in 930f1b6d2166
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/lib/ruby/gems/2.7.0 directory.
The command '/bin/sh -c gem install fluent-plugin-s3' returned a non-zero code: 1
ERROR: Service 'fluentd' failed to build : Build failed

docker-compose.yml

version: '3'
services:
  fluentd:
    image: fluentd:vrfy
    build: ./fluentd
    hostname: fluentd
    ports:
      - 24224:24224
    restart: always
    environment:
      - FLUENTD_CONF=fluentd.conf

Dockerコンテナ起動

[root]# <任意のディレクトリ>
[root]# docker-compose up -d --build
Creating network "test_default" with the default driver
Building fluentd
Sending build context to Docker daemon  4.608kB
Step 1/5 : FROM fluentd:v1.14-1
 ---> 3134b06b92a8
Step 2/5 : COPY fluentd.conf /fluentd/etc/fluentd.conf
 ---> 11b88baef6d8
Step 3/5 : USER root
 ---> Running in d8c0c30347ca
Removing intermediate container d8c0c30347ca
 ---> a052609feec2
Step 4/5 : RUN gem install fluent-plugin-s3
 ---> Running in 3ede124e654c
Successfully installed jmespath-1.4.0
Successfully installed aws-partitions-1.506.0
Successfully installed aws-eventstream-1.2.0
Successfully installed aws-sigv4-1.4.0
Successfully installed aws-sdk-core-3.121.1
Successfully installed aws-sdk-kms-1.48.0
Successfully installed aws-sdk-s3-1.103.0
Successfully installed aws-sdk-sqs-1.44.0
Successfully installed fluent-plugin-s3-1.6.1
9 gems installed
Removing intermediate container 3ede124e654c
 ---> 301113ec3ce8
Step 5/5 : USER fluent
 ---> Running in 1df49cdde671
Removing intermediate container 1df49cdde671
 ---> cee86926b906
Successfully built cee86926b906
Successfully tagged fluentd:vrfy
Creating test_fluentd_1 ... done
[root]#
タイトルとURLをコピーしました