I want to create one docker container with minio and also create one bucket at once.When I try to go to the console (localhost:9001) I get an error. Whats wrong with my docker-compose
?
docker-compose.yaml
:
version: '3'
services:
minio:
image: minio/minio:latest
container_name: minio
ports:
- 9000:9000
- 9001:9001
volumes:
- "./data:/data"
- "./config:/root/.minio"
environment:
MINIO_ACCESS_KEY: minio-access-key
MINIO_SECRET_KEY: minio-secret-key
command: server /data && server /minio-image/storage --console-address :9001
networks:
- minio-network
restart: always
create-bucket:
image: minio/mc:latest
container_name: create-post-bucket
environment:
MINIO_HOST: minio
MINIO_ACCESS_KEY: minio-access-key
MINIO_SECRET_KEY: minio-secret-key
entrypoint: ["sh", "-c"]
command: "mc mb local/post-bucket || true"
depends_on:
- minio
networks:
- minio-network
networks:
minio-network:
There are several issues in your docker-compose.yaml
.
When starting up the minio
container, the very first output is:
minio | WARNING: MINIO_ACCESS_KEY and MINIO_SECRET_KEY are deprecated.
minio | Please use MINIO_ROOT_USER and MINIO_ROOT_PASSWORD
So we should fix that.
Next, your command
seems problematic. You're running:
server /data && server /minio-image/storage --console-address :9001
But that entire command line gets passed as arguments to the minio
command, which doesn't make any sense. You probably want:
command: server /data/ --console-address :9001
The create-bucket
container attempts to run mc mb local/post-bucket
, but the local
alias is invalid:
[root@e874a3d8e8c8 /]# mc alias list local
local
URL : http://localhost:9000
AccessKey :
SecretKey :
API :
Path : auto
The minio service isn't running on localhost
. The MINIO_HOST
environment variable isn't used by the minio client. According to this documentation, you can provide a configuration in the MC_HOST_<hostname>
environment variable.
Additionally, the way your create-bucket
container is configured, it may start up and run before minio is ready to service requests, causing it to fail.
Using a bind mount (./data:/data
) instead of named volume is often sub-optimal because it leads to uid/gid conflicts between the host and container. Unless you really need to share the contents of that directory between the host and container, you're better off using a named volumethe contents of that directory between the host and container, you're better off using a named volume.
We can fix all of these issues with the following docker-compose.yaml
:
services:
minio:
image: minio/minio:latest
ports:
- 9000:9000
- 9001:9001
volumes:
- minio-data:/data
environment:
MINIO_ROOT_USER: $MINIO_ROOT_USER
MINIO_ROOT_PASSWORD: $MINIO_ROOT_PASSWORD
command: server /data --console-address :9001
restart: unless-stopped
create-bucket:
image: minio/mc:latest
environment:
MC_HOST_minio: http://${MINIO_ROOT_USER}:${MINIO_ROOT_PASSWORD}@minio:9000
entrypoint:
- sh
- -c
- |
until mc ls minio > /dev/null 2>&1; do
sleep 0.5
done
mc mb minio/post-bucket
volumes:
minio-data:
This assumes that you're setting MINIO_ROOT_USER
and MINIO_ROOT_PASSWORD
in your .env
file, like this:
MINIO_ROOT_USER=admin
MINIO_ROOT_PASSWORD=minio-secret-key
The entrypoint
script in the create-bucket
container loops until minio
is ready to service requests; then it creates the bucket.
Running docker-compose up
with this configuration results in:
Creating network "container_default" with the default driver
Creating volume "container_minio-data" with default driver
Creating container_minio_1 ... done
Creating create-post-bucket ... done
Attaching to container_minio_1, create-post-bucket
minio_1 | Formatting 1st pool, 1 set(s), 1 drives per set.
minio_1 | WARNING: Host local has more than 0 drives of set. A host failure will result in data becoming unavailable.
minio_1 | MinIO Object Storage Server
minio_1 | Copyright: 2015-2023 MinIO, Inc.
minio_1 | License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html>
minio_1 | Version: RELEASE.2023-06-02T23-17-26Z (go1.19.9 linux/amd64)
minio_1 |
minio_1 | Status: 1 Online, 0 Offline.
minio_1 | S3-API: http://192.168.192.2:9000 http://127.0.0.1:9000
minio_1 | Console: http://192.168.192.2:9001 http://127.0.0.1:9001
minio_1 |
minio_1 | Documentation: https://min.io/docs/minio/linux/index.html
minio_1 | Warning: The standard parity is set to 0. This can lead to data loss.
create-post-bucket | Bucket created successfully `minio/post-bucket`.
create-post-bucket exited with code 0
At this point, I can access the minio console as expected at http://localhost:9001 on my docker host.