Sign inSign up

wicos/mongodb-tools

By wicos

•Updated 12 months ago

Image
0

602

wicos/mongodb-tools repository overview

⁠MongoDB Database Tools Docker Image

⁠MongoDB 数据库工具 Docker 镜像

Docker License

A lightweight Docker image containing MongoDB Database Tools (mongodump, mongorestore, etc.) based on Ubuntu 24.04, designed for one-off executions and backup/restore operations.

基于 Ubuntu 24.04 的轻量级 Docker 镜像,包含 MongoDB 数据库工具(mongodump、mongorestore 等),专为一次性执行和备份/恢复操作而设计。

⁠Features / 特性

  • Based on Ubuntu 24.04 / 基于 Ubuntu 24.04
  • Contains MongoDB Database Tools v100.13.0 / 包含 MongoDB 数据库工具 v100.13.0
  • Includes MongoDB Shell (mongosh) v2.5.9 / 包含 MongoDB Shell (mongosh) v2.5.9
  • Optimized for one-off executions / 专为一次性执行优化
  • Minimal image size (429MB) / 最小化镜像大小 (429MB)
  • All tools available in /usr/local/bin and /usr/bin / 所有工具可在 /usr/local/bin 和 /usr/bin 中使用

⁠Included Tools / 包含的工具

  • mongodump - Create database backups / 创建数据库备份
  • mongorestore - Restore database backups / 恢复数据库备份
  • mongoexport - Export data to JSON, CSV, or TSV / 导出数据到 JSON、CSV 或 TSV
  • mongoimport - Import data from JSON, CSV, or TSV / 从 JSON、CSV 或 TSV 导入数据
  • mongostat - View MongoDB statistics / 查看 MongoDB 统计信息
  • mongotop - Track MongoDB performance / 跟踪 MongoDB 性能
  • bsondump - Convert BSON to JSON / 将 BSON 转换为 JSON
  • mongofiles - Manipulate files stored in GridFS / 操作存储在 GridFS 中的文件
  • mongosh - MongoDB Shell for interactive database operations / MongoDB Shell 用于交互式数据库操作

⁠Quick Start / 快速开始

⁠Pull the image / 拉取镜像
docker pull mongodb-tools:latest
⁠Build the image / 构建镜像
git clone <repository-url>
cd mongodb_tools
docker build -t mongodb-tools .

构建后的镜像大小约为 429MB,包含所有 MongoDB 数据库工具和 Shell。

⁠Usage / 使用方法

⁠Basic mongodump example / 基本 mongodump 示例
# Display help / 显示帮助
docker run --rm mongodb-tools mongodump --help

# Backup a local database / 备份本地数据库
docker run --rm -v /path/to/backup:/backup mongodb-tools mongodump --uri="mongodb://host:27017/dbname" --out /backup
⁠Basic mongosh example / 基本 mongosh 示例
# Display help / 显示帮助
docker run --rm mongodb-tools mongosh --help

# Connect to MongoDB using mongosh / 使用 mongosh 连接到 MongoDB
docker run --rm -it mongodb-tools mongosh "mongodb://host:27017/dbname"

# Execute a command with mongosh / 使用 mongosh 执行命令
docker run --rm mongodb-tools mongosh "mongodb://host:27017/dbname" --eval "db.collection.find().limit(5)"
⁠Basic mongorestore example / 基本 mongorestore 示例
# Display help / 显示帮助
docker run --rm mongodb-tools mongorestore --help

# Restore a database / 恢复数据库
docker run --rm -v /path/to/backup:/backup mongodb-tools mongorestore --uri="mongodb://host:27017/dbname" /backup/dbname
⁠Export and Import examples / 导出和导入示例
# Export collection to JSON / 导出集合到 JSON
docker run --rm -v /path/to/export:/export mongodb-tools mongoexport --uri="mongodb://host:27017/dbname" --collection=collection_name --out=/export/data.json

# Import JSON data / 导入 JSON 数据
docker run --rm -v /path/to/import:/import mongodb-tools mongoimport --uri="mongodb://host:27017/dbname" --collection=collection_name --file=/import/data.json
⁠Interactive MongoDB operations / 交互式 MongoDB 操作
# Start an interactive mongosh session / 启动交互式 mongosh 会话
docker run --rm -it mongodb-tools mongosh "mongodb://username:password@host:27017/dbname"

# Use mongosh for database administration / 使用 mongosh 进行数据库管理
docker run --rm -it mongodb-tools mongosh "mongodb://host:27017/admin" --eval "db.createUser({user: 'admin', pwd: 'password', roles: ['root']})"

⁠Advanced Usage / 高级用法

⁠Using environment variables / 使用环境变量
# Set MongoDB URI as environment variable / 将 MongoDB URI 设置为环境变量
docker run --rm -e MONGO_URI="mongodb://username:password@host:27017/dbname" \
  -v /path/to/backup:/backup \
  mongodb-tools mongodump --uri="$MONGO_URI" --out /backup
⁠Working with authentication / 使用认证
# Backup with authentication / 使用认证备份
docker run --rm -v /path/to/backup:/backup mongodb-tools \
  mongodump --uri="mongodb://username:password@host:27017/dbname?authSource=admin" --out /backup

⁠Building from Source / 从源代码构建

# Clone the repository / 克隆仓库
git clone <repository-url>
cd mongodb_tools

# Build the image / 构建镜像
docker build -t mongodb-tools:latest .

# Verify the build / 验证构建
docker run --rm mongodb-tools mongodump --version

⁠Configuration / 配置

⁠Build arguments / 构建参数
  • MONGO_TOOLS_URL: MongoDB tools download URL / MongoDB 工具下载 URL
    • Default: https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2404-x86_64-100.13.0.tgz
  • MONGOSH_URL: MongoDB Shell download URL / MongoDB Shell 下载 URL
    • Default: https://downloads.mongodb.com/compass/mongodb-mongosh_2.5.9_amd64.deb
⁠Environment variables / 环境变量
  • DEBIAN_FRONTEND: Set to noninteractive during build / 构建期间设置为 noninteractive

⁠Volume Mounting / 卷挂载

For backup and restore operations, you'll need to mount volumes:

对于备份和恢复操作,您需要挂载卷:

# Mount local directory for backups / 挂载本地目录用于备份
docker run --rm -v /local/path/to/backups:/backup mongodb-tools mongodump --uri="mongodb://host:27017/dbname" --out /backup

# Mount local directory for restore / 挂载本地目录用于恢复
docker run --rm -v /local/path/to/backups:/backup mongodb-tools mongorestore --uri="mongodb://host:27017/dbname" /backup/dbname

⁠Networking / 网络

When connecting to MongoDB instances, ensure proper network connectivity:

连接到 MongoDB 实例时,确保正确的网络连接:

# Connect to local MongoDB / 连接到本地 MongoDB
docker run --rm --network=host mongodb-tools mongodump --uri="mongodb://localhost:27017/dbname"

# Connect to remote MongoDB / 连接到远程 MongoDB
docker run --rm mongodb-tools mongodump --uri="mongodb://remote-host:27017/dbname"

⁠Troubleshooting / 故障排除

⁠Common Issues / 常见问题
  1. Permission denied errors / 权限被拒绝错误

    • Ensure proper permissions on mounted volumes / 确保挂载卷具有正确的权限
    • Use docker run --user $(id -u):$(id -g) if needed / 如需要,使用 docker run --user $(id -u):$(id -g)
  2. Connection timeouts / 连接超时

    • Check network connectivity / 检查网络连接
    • Verify MongoDB is accessible from the container / 验证 MongoDB 可从容器访问
  3. Authentication failures / 认证失败

    • Verify credentials and authentication source / 验证凭据和认证源
    • Check if user has necessary permissions / 检查用户是否具有必要权限

⁠License / 许可证

This project is licensed under the Apache License 2.0 - see the LICENSE⁠ file for details.

本项目采用 Apache License 2.0 许可证 - 详情请参阅 LICENSE⁠ 文件。

⁠Contributing / 贡献

Contributions are welcome! Please feel free to submit a Pull Request.

欢迎贡献!请随时提交 Pull Request。

⁠Support / 支持

For issues and questions:

对于问题和疑问:

⁠Changelog / 更新日志

⁠v1.0.0
  • Initial release / 初始版本
  • MongoDB Database Tools v100.13.0 / MongoDB 数据库工具 v100.13.0
  • MongoDB Shell v2.5.9 / MongoDB Shell v2.5.9
  • Ubuntu 24.04 base image / Ubuntu 24.04 基础镜像
  • Optimized image size (429MB) / 优化镜像大小 (429MB)
  • Multi-stage build for minimal footprint / 多阶段构建以实现最小占用空间

⁠CI/CD with GitHub Actions / 使用 GitHub Actions 进行 CI/CD

This project includes automated build and deployment workflows using GitHub Actions.

本项目包含使用 GitHub Actions 的自动化构建和部署工作流程。

⁠Features / 特性
  • Automated Docker image building / 自动化 Docker 镜像构建
  • Multi-platform support (amd64, arm64) / 多平台支持 (amd64, arm64)
  • Automatic version tagging / 自动版本标签
  • Security vulnerability scanning / 安全漏洞扫描
  • Push to Docker Hub and GitHub Container Registry / 推送到 Docker Hub 和 GitHub Container Registry
⁠Quick Setup / 快速设置
  1. Configure Docker Hub credentials in GitHub Secrets / 在 GitHub Secrets 中配置 Docker Hub 凭据
  2. Update DOCKERHUB_USERNAME in the workflow file / 在工作流程文件中更新 DOCKERHUB_USERNAME
  3. Push to main branch or create a tag / 推送到主分支或创建标签

For detailed setup instructions, see .github/workflows/setup.md⁠.

有关详细设置说明,请参阅 .github/workflows/setup.md⁠。

⁠Workflow Files / 工作流程文件

For more information about the workflows, see .github/workflows/README.md⁠.

有关工作流程的更多信息,请参阅 .github/workflows/README.md⁠。

Tag summary

Content type

Image

Digest

sha256:4ac2d1159…

Size

163.3 MB

Last updated

12 months ago

docker pull wicos/mongodb-tools