docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > Docker搭建minio

使用Docker搭建minio的详细图文教程

作者:反方向的钟o.0

本文介绍了Docker配置镜像源的方法,以及如何在Docker中拉取镜像和创建运行容器,详细说明了使用MinIO创建Bucket、设置AccessKey、安装和配置Cpolar以及SpringBoot集成MinIO的步骤,需要的朋友可以参考下

一、docker配置镜像源问题

vi /etc/docker/daemon.json
{
  "registry-mirrors": ["https://4xxwxhl6.mirror.aliyuncs.com","https://mirror.iscas.ac.cn","https://docker.rainbond.cc","https://docker.nju.edu.cn","https://6kx4zyno.mirror.aliyuncs.com","https://mirror.baidubce.com","https://docker.m.daocloud.io","https://dockerproxy.com"]
}

二、docker拉取镜像

docker pull minio/minio
mkdir -p /opt/minio/config

mkdir -p /opt/minio/data
docker run \
-p 9000:9000 \
-p 9001:9001 \
--net=host \
--name minio \
-d --restart=always \
-e "MINIO_ACCESS_KEY=minio" \
-e "MINIO_SECRET_KEY=minio123" \
-v /opt/minio/data:/data \
-v /opt/minio/config:/root/.minio \
minio/minio server \
/data --console-address ":9001" -address ":9000"

注意:

查看minio

1、新建Bucket

2、 新建Access Key

虚拟机下载安装Cpolar

curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash

SpringBoot集成使用

#低版本的okhttp会报错提示         
 <dependency>
    <groupId>io.minio</groupId>
    <artifactId>minio</artifactId>
    <version>8.5.7</version>
  </dependency>
 
  <dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>4.10.0</version>
  </dependency>
    @Test
    void uploadtest(){
        try{
            String endPoint = "8.tcp.cpolar.top";
            int port = 13981;
            String accessKey = "YsBvivSZUGsRLfqL2JXL";
            String secretKey = "yuLLwPoxFjUUvn45bQ3rwmH49Pf8wGFGkZTpNGXa";
            MinioClient minioClient = MinioClient.builder()
                    .endpoint(endPoint,port,false)
                    .credentials(accessKey,secretKey)
                    .build();
            // 定义桶名和对象名称
            String bucketName = "gulimall";
            String objectName = "test.jpg";
            String filePath = "E:\\uploadFile\\gulimall/p23.png"; // 本地文件路径
            minioClient.uploadObject(
                    UploadObjectArgs.builder()
                            .bucket(bucketName)
                            .object(objectName)
                            .filename(filePath)
                            .build());
            System.out.println("上传测试成功........");
        }catch (Exception e){
            System.out.println("Error" + e);
        }
    }
Errorerror occurred
ErrorResponse(code = RequestTimeTooSkewed, message = The difference between the request time and the server's time is too large., bucketName = null, objectName = null, resource = /gulimall, requestId = 17EC67767F4197ED, hostId = dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8)
@Test
    void downLoad(){
        try {
            String endPoint = "8.tcp.cpolar.top";
            int port = 13981;
            String accessKey = "YsBvivSZUGsRLfqL2JXL";
            String secretKey = "yuLLwPoxFjUUvn45bQ3rwmH49Pf8wGFGkZTpNGXa";
            // 创建 MinIO 客户端
            MinioClient minioClient = MinioClient.builder()
                    .endpoint(endPoint,port,false)
                    .credentials(accessKey, secretKey)
                    .build();

            String bucketName = "gulimall";
            String objectName = "test.jap";
            String filePath = "E:\\downloadFile\\gulimall/p23.png"; // 本地文件路径
            // 下载文件
            minioClient.downloadObject(
                    DownloadObjectArgs.builder()
                            .bucket(bucketName)
                            .object(objectName)
                            .filename(filePath)
                            .build()
            );
            System.out.println("文件下载成功: " + filePath);

        } catch (Exception e) {
            System.out.println("Error occurred: " + e);
        }
    }

通过地址访问上传内容

总结 

到此这篇关于使用Docker搭建minio的文章就介绍到这了,更多相关Docker搭建minio内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文