42
28

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 5 years have passed since last update.

docker-composeでMinio起動時にデフォルトのbucketを作成する

Last updated at Posted at 2018-05-09

MySQLとかPostgresみたいに環境変数経由でデフォルトのbucketが作れれば楽なんですが、Minioは現状そうなってないので、docker-compose.ymlだけでデフォルトのbucketを作成する方法のメモです。

  • アクセスキー: AKIA_MINIO_ACCESS_KEY
  • シークレットキー: minio_secret_key
  • バケット名: mybucket
  • (リージョン): us-east-1
docker-compose.yml
version: '3'

services:
  minio:
    image: minio/minio:latest
    ports:
      - 19000:9000
    volumes:
      - ./data/minio/data:/export
      - ./data/minio/config:/root/.minio
    environment:
      MINIO_ACCESS_KEY: AKIA_MINIO_ACCESS_KEY
      MINIO_SECRET_KEY: minio_secret_key
    command: server /export 
  createbuckets:
    image: minio/mc
    depends_on:
      - minio
    entrypoint: >
      /bin/sh -c "
      until (/usr/bin/mc config host add myminio http://minio:9000 AKIA_MINIO_ACCESS_KEY minio_secret_key) do echo '...waiting...' && sleep 1; done;
      /usr/bin/mc mb myminio/mybucket;
      /usr/bin/mc policy download myminio/mybucket;
      exit 0;
      "

docker-compose upで起動。

% docker-compose up
Creating network "minio_default" with the default driver
Creating minio_minio_1 ... done
Creating minio_createbuckets_1 ... done
Attaching to minio_minio_1, minio_createbuckets_1
minio_1          |
minio_1          |  You are running an older version of Minio released 1 month ago
minio_1          |  Update: docker pull minio/minio:RELEASE.2018-05-04T23-13-12Z
minio_1          |
minio_1          |
createbuckets_1  | Added `myminio` successfully.
createbuckets_1  | mc: <ERROR> Unable to make bucket `myminio/mybucket`. Your previous request to create the named bucket succeeded and you already own it.
minio_1          | Drive Capacity: 18 GiB Free, 224 GiB Total
minio_1          |
minio_1          | Endpoint:  http://172.26.0.2:9000  http://127.0.0.1:9000
minio_1          | AccessKey: AKIA_MINIO_ACCESS_KEY
minio_1          | SecretKey: minio_secret_key
minio_1          |
minio_1          | Browser Access:
minio_1          |    http://172.26.0.2:9000  http://127.0.0.1:9000
minio_1          |
minio_1          | Command-line Access: https://docs.minio.io/docs/minio-client-quickstart-guide
minio_1          |    $ mc config host add myminio http://172.26.0.2:9000 AKIA_MINIO_ACCESS_KEY minio_secret_key
minio_1          |
minio_1          | Object API (Amazon S3 compatible):
minio_1          |    Go:         https://docs.minio.io/docs/golang-client-quickstart-guide
minio_1          |    Java:       https://docs.minio.io/docs/java-client-quickstart-guide
minio_1          |    Python:     https://docs.minio.io/docs/python-client-quickstart-guide
minio_1          |    JavaScript: https://docs.minio.io/docs/javascript-client-quickstart-guide
minio_1          |    .NET:       https://docs.minio.io/docs/dotnet-client-quickstart-guide
createbuckets_1  | Access permission for `myminio/mybucket` is set to `download`
minio_createbuckets_1 exited with code 0

http://localhost:19000/ にアクセスし、アクセスキー&シークレットキーでログイン、mybucketが表示されれば成功です。

ポイントは以下の2点。

  • minio/minioイメージの中にはmcコマンドが入っていないので、minio/mcイメージを別コンテナで起動してmc mbコマンドでバケットを作成
  • minio本体が起動する前にmcコマンドが走ってしまい失敗することがあるので、until & sleepで起動を待つ

他にも以下のようにminio(-server)単体でmkdirでディレクトリを作り、policy.jsonを置く方法もあります。カスタムしたpolicy.jsonを使いたい場合はこっちの方が楽かもしれません。

docker-compose.yml
    minio:
      image: minio/minio:latest
        (略)
      entrypoint: sh
      command: -c "
        mkdir -p /data/mybucket;
        mkdir -p /data/.minio.sys/buckets/mybucket;
        cp /policy.json /data/.minio.sys/buckets/mybucket/policy.json;
        /usr/bin/minio server /export;
       "
      volumes:
         - ./data/minio/data:/export
         - ./data/minio/config:/root/.minio
         - ./config/policy.json:/policy.json

参考: Create default buckets via environment variables in docker · Issue #4769 · minio/minio

42
28
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
42
28

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?