Automatically Creating Buckets in Minio with Laravel Sail


When developing Laravel applications to be hosted on Laravel Vapor, it is common to use Minio as the file storage service locally. Minio is compatible with Amazon S3, which eliminates the need to change any logic from production to local development.

However, you need to manually create the bucket in Minio through the web interface.

This process needs to be repeated whenever you run sail down -v or start working on a new project that utilizes Minio.

Fortunately, there is a way to automate the bucket creation using Laravel Sail. This guide will walk you through the steps of programmatically creating buckets in Minio.

Step 1: Update the docker-compose.yml File

To begin, open your project's docker-compose.yml file and add the following service under the services key:

  image: minio/mc
    - minio
    - './docker/minio:/etc/minio'
    - sail
  entrypoint: /etc/minio/

Step 2: Create the Script

Next, create a new file named in the docker/minio directory (you have to create this folder).

Add the following script to the file:


/usr/bin/mc config host add local ${AWS_ENDPOINT} ${AWS_ACCESS_KEY_ID} ${AWS_SECRET_ACCESS_KEY};
/usr/bin/mc rm -r --force local/${AWS_BUCKET};
/usr/bin/mc mb -p local/${AWS_BUCKET};
/usr/bin/mc policy set download local/${AWS_BUCKET};
/usr/bin/mc policy set public local/${AWS_BUCKET};
/usr/bin/mc anonymous set upload local/${AWS_BUCKET};
/usr/bin/mc anonymous set download local/${AWS_BUCKET};
/usr/bin/mc anonymous set public local/${AWS_BUCKET};

exit 0;

Step 3: Make the Script Executable

You then need to make the script file executable. Run the following command to grant the necessary permissions:

chmod +x docker/minio/

If you don't do this step, you might encounter the following error when running sail up:

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed:
unable to start container process: exec: "/etc/minio/": permission denied: unknown

Step 4: Run the Docker Containers

Start the Laravel Sail environment by running the following command:

sail up -d

This command will build and run the Docker containers defined in your project's docker-compose.yml file, including the minio-create-bucket service we added earlier.

Once the Docker containers are up and running, Laravel Sail will automatically execute the script, which will create the Minio bucket based on the provided environment variables.

Environment Variables

In this guide, i assume you are using the following environment variables in your .env file:


If you are experiencing issues with file uploads locally while using the laravel-vapor NPM package, you may need to follow the instructions outlined in this guide: Using Minio on Laravel Vapor Locally.

However, if you want guests to be able to upload files, you will need to modify the SignedStorageUrlController as shown in this commit (remove the Gate::authorize call).