2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Mountpoint for Amazon S3 をコンテナから実行してみる

Last updated at Posted at 2023-03-22

2023/3/21 時点の情報で作成しています。Mountpoint for Amazon S3 は現在アルファリリースであるため本番ワークロードには適しません。また将来的に動作や仕様が変更される可能性があります。動作を確認したバージョン: 0.2.0-b8363a4

はじめに

Mountpoint for Amazon S3 を Docker で試した際のメモです。コンテナ環境でとりあえずサクッと試してみたい方の参考になれば幸いです。

Mountpoint for Amazon S3 自体の概要や使い方は以下の記事に投稿しています。

Dockerfile

FROM rust:1.68.0 as Build

RUN apt-get update && apt-get install -y \
    clang\
    cmake \
    curl \
    fuse \
    git \
    libfuse-dev \
    pkg-config \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* \
 && git clone --recurse-submodules https://github.com/awslabs/mountpoint-s3.git \
 && cd mountpoint-s3 \
 && cargo build --release


FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y \
    ca-certificates \
    libfuse-dev \
    sudo \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

COPY --from=build /mountpoint-s3/target/release/mount-s3 /usr/local/bin/mount-s3

RUN chmod 777 /usr/local/bin/mount-s3

RUN useradd -ms /bin/bash mount-s3-user \
 && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
 && adduser mount-s3-user sudo

USER mount-s3-user

動作確認

コンテナ内で s3 バケットをマウントするには、特権モード (--privileged)で実行する必要がありますのでご注意ください。

# イメージビルド
docker image build -t mount-s3:v0.2.0 .

# コンテナ起動
docker container run --privileged --rm -it mount-s3:v0.2.0 bash

# S3バケットのマウント
mount-s3-user@ce43831fda04:~$ sudo mount-s3 <bucket_name> /mnt --allow-other --region ap-northeast-1
mount-s3-user@ce43831fda04:~$ ls -l /mnt/test.json
-rw-r--r-- 1 root root 306424 Feb 21 02:42 /mnt/test.json

EC2 on Docker での考慮事項

AWS 認証情報に EC2 の IAM ロールを使用する場合、コンテナ環境から IMDSv2 メタデータにアクセスできるようにするにはインスタンスメタデータオプションで IMDSv2 のホップ制限を 1 → 2 に増やす必要があります。

aws ec2 modify-instance-metadata-options \
    --instance-id i-xxxxxxxxxxxxxxxxx \
    --http-put-response-hop-limit 2 \
    --http-endpoint enabled

コンテナ環境では、ホップ制限が 1 の場合、コンテナへの到達は余分なネットワークホップと見なされるため、IMDSv2 応答は返されません。IMDSv1 へのフォールバックプロセスとその結果として生じる遅延を回避するために、コンテナ環境でホップ制限を 2 に設定することをお勧めします。

以上です。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?