对象存储, 开源MinIO docker-compose.yml 文件

python SDK 文档地址:

https://min.io/docs/minio/linux/developers/python/API.html

docker-compose.yml 文件

version: '3'

services:
  minio:
    image: quay.io/minio/minio
    container_name: minio
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      - MINIO_ROOT_USER={your user name}
      - MINIO_ROOT_PASSWORD={your password}
    volumes:
      - ./data:/data
      - ./config:/root/.minio
    logging:
      driver: "json-file"
      options:
        max-size: "10m" # 设置最大日志文件大小为10兆
    deploy:
      resources:
        limits:
          cpus: "0.5" # 设置使用的最大CPU核心数量
          memory: 512M # 设置最大内存使用量
    command: server /data --console-address ":9001"

经过验证,可以启动。
在这里插入图片描述

控制台使用:

  • 访问http://127.0.0.1:9001/
  • 登录一下(用户名和密码在 docker-compose 文件中已经配置)
  • 配置 bucket
  • 再配置 bucket 的accessKey, secretKey, 配置完后之后,可以下载这些配置文件为 json 文件到本地这个文件很重要, 在业务项目中会用到。

应用服务中使用样例:

MINIO_HOST="127.0.0.1:9000"
MINIO_BUCKET_NAME="your bucket name"
MINIO_ACCESS_KEY="your access key"
MINIO_SECRET_KEY="your secret key"

from minio import Minio

# 配置连接信息
minio_client = Minio(
    MINIO_HOST,
    access_key=MINIO_ACCESS_KEY,
    secret_key=MINIO_SECRET_KEY,
    secure=False,
)  # 设置为 True 表示使用 HTTPS

# 检查桶是否存在
bucket_name = MINIO_BUCKET_NAME
if minio_client.bucket_exists(bucket_name):
    print("存在")
  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Minio is an open-source object storage server that provides a scalable and secure file storage system, often used as an alternative to Amazon S3. Docker Compose is a tool for defining and running multi-container Docker applications. When you combine Minio with Docker Compose, you can easily set up and manage a Minio instance within a Docker environment. To create a `docker-compose.yml` file for Minio, you'll define the necessary services, networks, and volumes. Here's a basic outline of what a `docker-compose.yml` configuration might look like: ```yaml version: '3' services: minio: image: minio/minio container_name: minio_server ports: - "9000:9000" # HTTP port - "9001:9001" # HTTPS port (optional) environment: MINIO_ACCESS_KEY: your-access-key MINIO_SECRET_KEY: your-secret-key MINIO_ROOT_USER: your-username MINIO_ROOT_PASSWORD: your-password volumes: - ./data/minio:/data networks: - minio-net networks: minio-net: driver: overlay volumes: minio-data: ``` In this example: - `image`: Uses the official Minio Docker image. - `ports`: Maps the container ports to host ports for accessing Minio. - `environment`: Sets up environment variables for authentication and other settings. - `volumes`: Mounts a local directory to persist data within the host machine. - `networks`: Creates a network for the service to communicate within the compose setup. Here are some related questions: 1. What is the purpose of specifying the `MINIO_ROOT_USER` and `MINIO_ROOT_PASSWORD`? 2. How does mounting a volume ensure data persistence when using Minio in Docker? 3. Can you explain the difference between using `9000` and `9001` ports in the configuration?

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值