在启动 MinIO 时,是不是看见了一大串红色字体,如下:
No credential environment variables defined. Going with the defaults. It is strongly recommended to define your own credentials via environment variables MINIO_ROOT_USER and MINIO_ROOT_PASSWORD instead of using default values
这是因为我们没有指定自定义的 Access Key 和 Secret Key。可以使用如下指令,在启动 MinIO 时指定自定义 Access Key 和 Secret Key:
[root@localhost ~]# docker run -p 9000:9000 --name minio \ > -e "MINIO_ACCESS_KEY=root" \ > -e "MINIO_SECRET_KEY=mypassword" \ > -v /root/data:/data \ > -v /root/config:/root/.minio \ > minio/minio server /data WARNING: MINIO_ACCESS_KEY and MINIO_SECRET_KEY are deprecated. Please use MINIO_ROOT_USER and MINIO_ROOT_PASSWORD Endpoint: http://172.17.0.2:9000 http://127.0.0.1:9000 Browser Access: http://172.17.0.2:9000 http://127.0.0.1:9000 Object API (Amazon S3 compatible): Go: https://docs.min.io/docs/golang-client-quickstart-guide Java: https://docs.min.io/docs/java-client-quickstart-guide Python: https://docs.min.io/docs/python-client-quickstart-guide JavaScript: https://docs.min.io/docs/javascript-client-quickstart-guide .NET: https://docs.min.io/docs/dotnet-client-quickstart-guide IAM initialization complete
此时,我们就可以使用自定义的 Access Key 和 Secret Key 访问 MinIO 了。注意:Access Key 长度至少为 3,Secret Key 长度至少为 8。否则,将抛出如下错误信息:
ERROR Unable to validate credentials inherited from the shell environment: Invalid credentials > Please provide correct credentials HINT: Access key length should be at least 3, and secret key length at least 8 characters
在 Windows 中,执行如下命令即可:
docker run -p 9000:9000 --name minio1 \ -e "MINIO_ACCESS_KEY=root" \ -e "MINIO_SECRET_KEY=mypassword" \ -v D:\data:/data \ -v D:\minio\config:/root/.minio \ minio/minio server /data
要覆盖 MinIO 的自动生成的密钥,你可以把 Access Key 和 Secret Key创建成 Docker secrets。MinIO 允许常规字符串作为 Access Key 和 Secret Key。命令如下:
[root@localhost ~]# echo "root" | docker secret create access_key - 10z41srebt5chnooksqg0xkh3 [root@localhost ~]# echo "mypassword" | docker secret create secret_key - kdovu1buqs0g5uk65tax8ti80
使用 docker service 创建 MinIO 服务,并读取 Docker secrets。命令如下:
[root@localhost ~]# docker service create --name="minio-service" --secret="access_key" --secret="secret_key" minio/minio server /data vqgbgk1pfvs6w01jbcisybn2e overall progress: 1 out of 1 tasks 1/1: running [==================================================>] verify: Service converged
在 Docker 中可以使用 docker ps -a 命令, 获取上面创建的名为 minio-service 的容器ID。命令如下:
[root@localhost ~]# docker ps -a | grep minio-service ac4b9d8e2e7c minio/minio:latest "/usr/bin/docker-ent…" 2 minutes ago Up 2 minutes 9000/tcp minio-service.1.rq17m9ovodkgsod7o446g6zfe
上面命令中,-a 可确保你获取所有的容器(创建的,正在运行的,退出的),然后从输出中获取容器ID。
启动容器,你可以使用 docker start 命令。如下:
[root@localhost ~]# docker start ac4b9d8e2e7c ac4b9d8e2e7c [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ac4b9d8e2e7c minio/minio:latest "/usr/bin/docker-ent…" 6 minutes ago Up 6 minutes 9000/tcp minio-service.1.rq17m9ovodkgsod7o446g6zfe
停止一下正在运行的容器, 使用 docker stop 命令。如下:
[root@localhost ~]# docker stop ac4b9d8e2e7c ac4b9d8e2e7c [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker 中可以使用 docker logs 命令,获取容器日志。如果要获取 MinIO 日志,执行如下命令:
[root@localhost ~]# docker logs ac4b9d8e2e7c Endpoint: http://172.17.0.2:9000 http://127.0.0.1:9000 Browser Access: http://172.17.0.2:9000 http://127.0.0.1:9000 Object API (Amazon S3 compatible): Go: https://docs.min.io/docs/golang-client-quickstart-guide Java: https://docs.min.io/docs/java-client-quickstart-guide Python: https://docs.min.io/docs/python-client-quickstart-guide JavaScript: https://docs.min.io/docs/javascript-client-quickstart-guide .NET: https://docs.min.io/docs/dotnet-client-quickstart-guide IAM initialization complete Exiting on signal: TERMINATED Endpoint: http://172.17.0.3:9000 http://127.0.0.1:9000 Browser Access: http://172.17.0.3:9000 http://127.0.0.1:9000 Object API (Amazon S3 compatible): Go: https://docs.min.io/docs/golang-client-quickstart-guide Java: https://docs.min.io/docs/java-client-quickstart-guide Python: https://docs.min.io/docs/python-client-quickstart-guide JavaScript: https://docs.min.io/docs/javascript-client-quickstart-guide .NET: https://docs.min.io/docs/dotnet-client-quickstart-guide IAM initialization complete
监控 MinIO 容器使用的资源,使用 docker stats 命令。如下:
[root@localhost ~]# docker stats ac4b9d8e2e7c CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS ac4b9d8e2e7c minio-service.1.rq17m9ovodkgsod7o446g6zfe 0.00% 40.75MiB / 1.777GiB 2.24% 6.84kB / 1.56kB 0B / 2.65MB 6