Skip to content

Add MinIO Container

ucan-lab edited this page Jun 14, 2023 · 3 revisions

MinIO

compose.yml

https://hub.docker.com/r/minio/minio

volumes:
  minio-store:

services:
  app:
    # ...
    environment:
      - AWS_ACCESS_KEY_ID=${MINIO_ACCESS_KEY}
      - AWS_SECRET_ACCESS_KEY=${MINIO_SECRET_KEY}
      - AWS_DEFAULT_REGION=us-east-1
      - AWS_BUCKET=laravel-local
      - AWS_ENDPOINT=http://localhost:9000

  minio:
    image: minio/minio
    ports:
      - target: 9000
        published: ${MINIO_PORT:-9000}
        protocol: tcp
        mode: host
    volumes:
      - type: volume
        source: minio-store
        target: /data
        volume:
          nocopy: true
    environment:
      MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
      MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
    command: server /data

Add MINIO key to docker-compose's .env

MINIO_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXX
MINIO_SECRET_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  • .env in the project root
  • The contents of the key can be anything

MINIO settings

$ docker compose up -d
  • http://localhost:9000
    • Enter your access key and secret key to log in
  • Create a laravel-local bucket to match the AWS_BUCKET environment variable

Install league/flysystem-aws-s3-v3

https://github.com/thephpleague/flysystem-aws-s3-v3

$ docker compose exec app bash
$ composer require league/flysystem-aws-s3-v3:^1.0

Edit backend/config/filesystems.php

return [
    'disks' => [
        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
            'endpoint' => env('AWS_ENDPOINT'),
            // Add
            'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', true),
        ],
    ],
    // ...
];

Example of uploading a file

$ docker compose exec app bash
$ php artisan tinker

>>> use Illuminate\Support\Facades\Storage;

>>> Storage::disk('s3')->put('example.txt', 'Contents');
=> true

>>> Storage::disk('s3')->get('example.txt');
=> "Contents"

http://localhost:9000/minio/laravel-local