4
2

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.

minio docker-composeした時にバケットを自動的に作成する

Last updated at Posted at 2023-03-15

ググっていろいろな記事を参考にしたけど、結局はコピペで動作しなかったので動くように頑張った。

目的

miniodocker-composeで起動しバケットを自動で作成したい。

ググって試すも動作しなかった

mkcertで証明書を作成

brew install mkcert nss
mkcert -install
mkdir mkcert
mkcert -cert-file mkcert/public.crt -key-file mkcert/private.key localhost 127.0.0.1

トライ

docker-compose.yml
minio:
    image: minio/minio:latest
    ports:
        - 9000:9000
        - 9090:9090
    environment:
        - MINIO_ROOT_USER=minioadmin
        - MINIO_ROOT_PASSWORD=minioadmin
        - MINIO_SERVER_URL=https://localhost:9000
    entrypoint: sh
    command: -c "
        cd ./docker/minio;
        minio server /data --address :9000 --console-address :9090;"
    volumes:
        - ./mkcert:/root/.minio/certs

minio_createbuckets:
    image: minio/mc:latest
    depends_on:
        - minio
    entrypoint: >
        /bin/sh -c "
        mc alias set minioio https://minio:9000 minioadmin minioadmin;
        mc mb --ignore-existing minioio/test;
        mc anonymous set public minioio/test;
        exit 0;"

結果

参考記事の記述の通り試すも失敗

mc: <ERROR> Unable to initialize new alias from the provided credentials. Get "https://minio:9000": dial tcp 127.0.0.1:9000: connect: connection refused.

原因はminio/mcのコンテナの方に証明書の設置が必要だった

mkcertで証明書を作成

brew install mkcert nss
mkcert -install
mkdir mkcert
mkcert -cert-file mkcert/public.crt -key-file mkcert/private.key localhost minio 127.0.0.1

トライ

動作しなかったdocker-compose.ymlとの差分は変更点を確認ください。

docker-compose.yml
minio:
    image: minio/minio:latest
    ports:
        - 9000:9000
        - 9090:9090
    environment:
        - MINIO_ROOT_USER=minioadmin
        - MINIO_ROOT_PASSWORD=minioadmin
        - MINIO_SERVER_URL=http://localhost:9000
    entrypoint: sh
    command: -c "
        cd ./docker/minio;
        minio server /data --address :9000 --console-address :9090;"
    volumes:
        - ./mkcert:/root/.minio/certs

minio_createbuckets:
    image: minio/mc:latest
    depends_on:
        - minio
    entrypoint: >
        /bin/sh -c "
        mc alias set minioio https://minio:9000 minioadmin minioadmin;
        mc mb --ignore-existing minioio/test;
        mc anonymous set public minioio/test;
        exit 0;"
    # 変更点
    volumes:
        - ./mkcert:/root/.mc/certs/CAs

結果

mc alias set minioio https://minio:9000 minioadmin minioadmin;の実行結果

Added `minioio` successfully.

参考

記事作成時の各コンテナのバージョン
minio/minio:RELEASE.2023-03-13T19-46-17Z
minio/mc:RELEASE.2023-02-28T00-12-59Z

4
2
1

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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?