thumbororg/thumborThumbor官方Docker镜像是开源实时图片处理服务Thumbor的容器化部署方案。Thumbor能够对图片进行实时处理,包括裁剪、缩放、旋转、滤镜应用、格式转换等操作,同时提供安全的URL签名机制,防止未授权图片处理请求,广泛应用于需要动态优化图片资源的场景。
通过以下命令启动基础Thumbor服务:
bashdocker run -d -p 8888:8888 --name thumbor thumbor/thumbor
-p 8888:8888:映射容器8888端口到主机,Thumbor默认监听8888端口--name thumbor:指定容器名称为thumbor通过环境变量自定义Thumbor配置,常用变量如下:
| 环境变量 | 描述 | 默认值 |
|---|---|---|
THUMBOR_PORT | 服务监听端口 | 8888 |
SECURITY_KEY | 用于生成安全URL的密钥 | 空(建议生产环境必须设置) |
MAX_WIDTH | 最大图片宽度限制 | 0(无限制) |
MAX_HEIGHT | 最大图片高度限制 | 0(无限制) |
STORAGE_BACKEND | 图片存储后端(如thumbor.storage.file_storage) | thumbor.storage.file_storage |
RESULT_STORAGE_BACKEND | 处理结果存储后端 | thumbor.result_storages.file_storage |
CACHE_BACKEND | 缓存后端(如thumbor.cache.file_cache) | thumbor.cache.file_cache |
示例:带安全密钥和端口配置的启动命令
bashdocker run -d \ -p 9000:9000 \ -e THUMBOR_PORT=9000 \ -e SECURITY_KEY=my_secure_key_123 \ --name thumbor-secure \ thumbor/thumbor
如需持久化存储图片或配置文件,可挂载主机目录到容器:
/data/thumbor/storage:存储原始图片的目录/data/thumbor/result_storage:存储处理后图片的目录/data/thumbor/cache:缓存目录/etc/thumbor:自定义配置文件目录(需包含thumbor.conf)示例:挂载存储和缓存目录
bashdocker run -d \ -p 8888:8888 \ -v /host/path/storage:/data/thumbor/storage \ -v /host/path/cache:/data/thumbor/cache \ --name thumbor-persistent \ thumbor/thumbor
以下是使用Docker Compose部署Thumbor的示例(含持久化存储和安全配置):
yamlversion: '3' services: thumbor: image: thumbor/thumbor ports: - "8888:8888" environment: - SECURITY_KEY=your_secure_key_here - MAX_WIDTH=2000 - MAX_HEIGHT=2000 - CACHE_BACKEND=thumbor.cache.file_cache volumes: - ./storage:/data/thumbor/storage - ./cache:/data/thumbor/cache restart: unless-stopped
服务启动后,可通过访问以下URL测试基础功能(需替换[IMAGE_URL]为实际图片URL):
http://localhost:8888/unsafe/300x200/[IMAGE_URL]
unsafe:未签名模式(仅测试用,生产环境需使用安全签名URL)300x200:目标图片尺寸(宽度x高度)[IMAGE_URL]:原始图片的URL(需URL编码)SECURITY_KEY并使用签名URL,避免未授权图片处理--memory参数)manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务