Below is a service in my docker compose.
minio:
image: minio/minio:edge
environment:
MINIO_ACCESS_KEY: minio123
MINIO_SECRET_KEY: minio123
volumes:
- datastore:/data
ports:
- 9000:9000
networks:
- devnetwork
command: server /data
i tried multiple commands like the following:
mc policy set public myminio/mybucket
always get the below error when i try access an image in my bucket
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied.</Message>
<Key>images/281c1458-41cd-4e1e-b6d5-b7243b9ac650.jpg</Key>
<BucketName>mybucket</BucketName>
<Resource>/mybucket/images/281c1458-41cd-4e1e-b6d5-b7243b9ac650.jpg</Resource>
<RequestId>1667FAC6085F2E6C</RequestId>
<HostId>9159f2da-4de3-4300-91fe-d59a41d883c4</HostId>
</Error>
You can add mc to the docker-compose as seen here - https://github.com/minio/minio/issues/4769
Updating a bit for changes that have happened in the mc commands, it would look something like this:
version: "2"
services:
minio:
image: minio/minio
ports:
- "9000:9000"
volumes:
- datastore:/data
environment:
- "MINIO_ACCESS_KEY=minio"
- "MINIO_SECRET_KEY=minio123"
command: server /data
createbuckets:
image: minio/mc
depends_on:
- minio
entrypoint: >
/bin/sh -c "
/usr/bin/mc alias set myminio http://minio:9000 minio minio123;
/usr/bin/mc mb myminio/somebucketname;
/usr/bin/mc policy set public myminio/somebucketname;
exit 0;
"
Another approach to create a bucket on MinIO startup and make it public using Docker Compose (note the MinIO version - older versions do not include mc, so this solution may not work):
services:
minio:
image: quay.io/minio/minio:RELEASE.2024-05-28T17-19-04Z
environment:
MINIO_ROOT_USER: minio-user
MINIO_ROOT_PASSWORD: minio-password
MINIO_UPDATE: off
entrypoint: >
/bin/sh -c '
isAlive() { curl -sf http://127.0.0.1:9000/minio/health/live; } # check if Minio is alive
minio $0 "$@" --quiet & echo $! > /tmp/minio.pid # start Minio in the background
while ! isAlive; do sleep 0.1; done # wait until Minio is alive
mc alias set minio http://127.0.0.1:9000 minio-user minio-password # setup Minio client
mc mb minio/test-bucket || true # create a test bucket
mc anonymous set public minio/test-bucket # make the test bucket public
kill -s INT $(cat /tmp/minio.pid) && rm /tmp/minio.pid # stop Minio
while isAlive; do sleep 0.1; done # wait until Minio is stopped
exec minio $0 "$@" # start Minio in the foreground
'
command: server /data --json --console-address ':9090'
ports: ['9000:9000/tcp', '9090:9090/tcp'] # open http://127.0.0.1:9090 (9000 is the API port)
volumes: [minio-data:/data:rw]
healthcheck:
test: ['CMD', 'curl', '-f', 'http://127.0.0.1:9000/minio/health/live']
interval: 10s
start_interval: 1s
start_period: 10s
security_opt: [no-new-privileges:true]
volumes:
minio-data: {}

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With