Docker 安装 (完整详细版)
Docker 日常命令大全(完整详细版)
Minio 是一个基于Apache License v2.0开源协议的对象存储服务,虽然轻量,却拥有着不错的性能。它兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据。
例如图片、视频、日志文件、备份数据和容器/虚拟机镜像等,而一个对象文件可以是任意大小,从几 kb 到最大 5T 不等。
Docker如果想安装软件 , 必须先到 Docker 镜像仓库下载镜像。
Docker官方镜像
命令 | 描述 |
---|---|
docker pull minio/minio | 下载最新版Minio镜像 (其实此命令就等同于 : docker pull minio/minio:latest ) |
docker pull minio/minio:RELEASE.2022-06-20T23-13-45Z.fips | 下载指定版本的Minio镜像 (xxx指具体版本号) |
检查当前所有Docker下载的镜像
docker images
一个用来存放配置,一个用来存储上传文件的目录
启动前需要先创建Minio外部挂载的配置文件( /home/minio/config),和存储上传文件的目录( /home/minio/data)
-
mkdir -p
/home
/minio
/config
-
mkdir -p
/home
/minio
/
data
多行模式
-
docker
run -p
9000:
9000 -p
9090:
9090 \
-
--net
=host \
-
--name minio \
-
-d --restart
=always \
-
-e
"MINIO_ACCESS_KEY=minioadmin" \
-
-e
"MINIO_SECRET_KEY=minioadmin" \
-
-v
/home
/minio
/
data:
/
data \
-
-v
/home
/minio
/config:
/root
/.minio \
-
minio
/minio server \
-
/
data --console-address
":9090" -
address
":9000"
单行模式
docker run -p 9000:9000 -p 9090:9090 --net=host --name minio -d --restart=always -e "MINIO_ACCESS_KEY=minioadmin" -e "MINIO_SECRET_KEY=minioadmin" -v /home/minio/data:/data -v /home/minio/config:/root/.minio minio/minio server /data --console-address ":9090" -address ":9000"
9090端口指的是minio的客户端端口
MINIO_ACCESS_KEY :账号
MINIO_SECRET_KEY :密码(账号长度必须大于等于5,密码长度必须大于等于8位)
访问:http://192.168.124.132:9090/login 用户名:密码 minioadmin:minioadmin
创建组
创建accessKey和secretKey
文件内容如下,保存文件,SDK操作文件的API需要用到
{"url":"http://192.168.124.132:9000","accessKey":"XO1JDovW2FTmGaBb","secretKey":"uG6wMfylUnOVH5WzwxqnldOWw2dMshNX","api":"s3v4","path":"auto"}
创建Bucket
上传文件
官方文档:https://docs.min.io/docs/
javaSDK:https://docs.min.io/docs/java-client-quickstart-guide.html
maven依赖
-
#低版本的okhttp会报错提示
-
<dependency
>
-
<groupId
>com.squareup.okhttp
3
<
/groupId
>
-
<artifactId
>okhttp
<
/artifactId
>
-
<version
>
4.9.0
<
/version
>
-
<
/dependency
>
-
-
<dependency
>
-
<groupId
>io.minio
<
/groupId
>
-
<artifactId
>minio
<
/artifactId
>
-
<version
>
8.4.2
<
/version
>
-
<exclusions
>
-
<exclusion
>
-
<artifactId
>okhttp
<
/artifactId
>
-
<groupId
>com.squareup.okhttp
3
<
/groupId
>
-
<
/exclusion
>
-
<
/exclusions
>
-
<
/dependency
>
测试文件上传
-
import io.minio.BucketExistsArgs;
-
import io.minio.MakeBucketArgs;
-
import io.minio.MinioClient;
-
import io.minio.UploadObjectArgs;
-
import io.minio.errors.MinioException;
-
-
import java.io.IOException;
-
import java.security.InvalidKeyException;
-
import java.security.NoSuchAlgorithmException;
-
-
public
class
FileUploader {
-
-
public
static
void
main
(String[] args)
throws IOException, NoSuchAlgorithmException, InvalidKeyException {
-
try {
-
// Create a minioClient with the MinIO server playground, its access key and secret key.
-
MinioClient
minioClient
=
-
MinioClient.builder()
-
.endpoint(
"http://192.168.124.132:9000")
-
.credentials(
"XO1JDovW2FTmGaBb",
"uG6wMfylUnOVH5WzwxqnldOWw2dMshNX")
-
.build();
-
-
// Make 'asiatrip' bucket if not exist.
-
boolean
found
= minioClient.bucketExists(BucketExistsArgs.builder().bucket(
"public").build());
-
if (!found) {
-
// Make a new bucket called 'asiatrip'.
-
minioClient.makeBucket(MakeBucketArgs.builder().bucket(
"public").build());
-
}
else {
-
System.out.println(
"Bucket 'public' already exists.");
-
}
-
-
// Upload '/home/user/Photos/asiaphotos.zip' as object name 'asiaphotos-2015.zip' to bucket
-
// 'asiatrip'.
-
minioClient.uploadObject(
-
UploadObjectArgs.builder()
-
.bucket(
"public")
-
.object(
"credentials.json")
-
.filename(
"C:/Users/lai.huanxiong/Downloads/credentials.json")
-
.build());
-
System.out.println(
"'C:/Users/lai.huanxiong/Downloads/credentials.json' is successfully uploaded as " +
"object 'credentials.json' to bucket 'public'.");
-
}
catch (MinioException e) {
-
System.out.println(
"Error occurred: " + e);
-
System.out.println(
"HTTP trace: " + e.httpTrace());
-
}
-
}
-
}
文件上传成功展示
至此,Docker搭建Minio服务器和简单操作完成!!!