Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FrankClark's avatar

Minio Programatically Create Bucket (sail)

Hello There,

Working on moving us over from Homestead to Docker. I'm using Sail.

Anyone know if there is a way to programatically create a public bucket in minio ? It's a very annoying manual step that needs to be done in the process.

After running sail up and building the containers, we need to manually log into the minio UI create the public bucket before we can seed the application with mock data.

Thanks.

0 likes
4 replies
cwhite's avatar
cwhite
Best Answer
Level 19

Yeah it's not too difficult, the trick is to create another container in your docker-compose that fires up after the minio container, runs a script and then exists:

// docker-compose
  createbuckets:
    container_name: 'minio-createbuckets'
    image: minio/mc
    depends_on:
      - minio
    environment:
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      AWS_BUCKET: ${AWS_BUCKET}
      AWS_BUCKET_PRIVATE: ${AWS_BUCKET_PRIVATE}
      AWS_ENDPOINT: ${AWS_ENDPOINT}
    volumes:
      - './docker/minio:/etc/minio'
    networks:
      - app-network
    entrypoint: /etc/minio/create_buckets.sh
// create_buckets.sh
#!/bin/sh

/usr/bin/mc config host add myminio ${AWS_ENDPOINT} ${AWS_ACCESS_KEY_ID} ${AWS_SECRET_ACCESS_KEY};
# /usr/bin/mc rm -r --force myminio/${AWS_BUCKET};
# /usr/bin/mc rm -r --force myminio/${AWS_BUCKET_PRIVATE};
/usr/bin/mc mb -p myminio/${AWS_BUCKET};
/usr/bin/mc policy set download myminio/${AWS_BUCKET};
/usr/bin/mc mb -p myminio/${AWS_BUCKET_PRIVATE};
/usr/bin/mc policy set none myminio/${AWS_BUCKET_PRIVATE};
exit 0;

https://github.com/minio/mc

1 like
FrankClark's avatar

@cwhite Thanks for getting back. I'm giving it a go, just need to figure out a permissions issue at the moment

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

@cwhite - This does seem to work BUT the bucket it creates is private. From what i have googled, this line : /usr/bin/mc policy set download myminio/${AWS_BUCKET}; should make the bucket public. Am i missing something here ?

FrankClark's avatar

Ah ok, i have been reading up on the docs and it makes sense, I have to set the anonymous policies. I threw the kitchen sink at it and now everything works. For anyone else reading this, i'd refine it to you your needs but this will essential result in a fully public bucket :

#!/bin/sh
/usr/bin/mc config host add myminio ${AWS_ENDPOINT} ${AWS_ACCESS_KEY_ID} ${AWS_SECRET_ACCESS_KEY};
# /usr/bin/mc rm -r --force myminio/${AWS_BUCKET};
# /usr/bin/mc rm -r --force myminio/${AWS_BUCKET_PRIVATE};
/usr/bin/mc mb -p myminio/${AWS_BUCKET};
/usr/bin/mc policy set download myminio/${AWS_BUCKET};
/usr/bin/mc policy set public myminio/${AWS_BUCKET};
/usr/bin/mc anonymous set upload myminio/${AWS_BUCKET};
/usr/bin/mc anonymous set download myminio/${AWS_BUCKET};
/usr/bin/mc anonymous set public myminio/${AWS_BUCKET};
exit 0;
1 like

Please or to participate in this conversation.