
arigaio/atlas本镜像为 Atlas 的官方 Docker 镜像。Atlas 是一款语言无关的数据库 schema 管理与迁移工具,基于现代 DevOps 原则设计,支持通过声明式或版本化工作流管理数据库结构,适用于各类数据库的 schema 生命周期管理。
MySQL、MariaDB、PostgreSQL、SQLite、TiDB、CockroachDB、SQL Server、ClickHouse、Redshift。
bashdocker pull arigaio/atlas:latest
bashdocker run --rm -it arigaio/atlas:latest --help
输出示例:
A database toolkit. Usage: atlas [command] Available Commands: completion Generate the autocompletion script for the specified shell help Help about any command license Display license information login Log in to Atlas Cloud logout Logout from Atlas Cloud migrate Manage versioned migration files schema Work with atlas schemas version Prints this Atlas CLI version information Flags: -h, --help help for atlas Use "atlas [command] --help" for more information about a command.
通过 schema inspect 命令获取数据库当前 schema:
bashdocker run --rm -it arigaio/atlas:latest \ schema inspect \ --url "mysql://user:password@host:port/dbname"
说明:
--url参数指定数据库连接串,格式为<driver>://<user>:<password>@<host>:<port>/<database>(不同数据库驱动语法略有差异,详见 官方文档)。
挂载本地 schema 文件(HCL/SQL),生成将数据库迁移至目标状态的计划:
bash# 本地目录结构:./schema/schema.hcl(定义目标 schema) docker run --rm -it \ -v $(pwd)/schema:/schema \ # 挂载本地 schema 目录至容器内 /schema arigaio/atlas:latest \ schema plan \ --url "mysql://user:password@host:port/dbname" \ # 目标数据库连接串 -f /schema/schema.hcl # 指定容器内 schema 文件路径
初始化迁移目录并生成迁移文件:
bash# 初始化迁移目录(本地 ./migrations) docker run --rm -it \ -v $(pwd)/migrations:/migrations \ # 挂载迁移文件目录 arigaio/atlas:latest \ migrate init \ --dir /migrations \ # 容器内迁移文件目录 --driver mysql # 指定数据库驱动 # 根据 schema 变更生成迁移文件 docker run --rm -it \ -v $(pwd)/migrations:/migrations \ -v $(pwd)/schema:/schema \ arigaio/atlas:latest \ migrate diff \ --dir /migrations \ --to /schema/schema.hcl \ # 目标 schema 文件 --driver mysql \ --dev-url "mysql://root:pass@dev-mysql:3306/dev_db" # 开发环境数据库(用于生成迁移)
以下示例通过 Docker Compose 集成 Atlas 与 MySQL,实现本地 schema 管理:
yamlversion: '3.8' services: # 目标数据库(MySQL) mysql: image: mysql:8.0 environment: MYSQL_ROOT_PASSWORD: rootpass MYSQL_DATABASE: app_db ports: - "3306:3306" healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u root", "-prootpass"] interval: 5s timeout: 5s retries: 5 # Atlas 服务(用于执行 schema 操作) atlas: image: arigaio/atlas:latest volumes: - ./schema:/schema # 挂载本地 schema 目录 - ./migrations:/migrations # 挂载迁移文件目录 depends_on: mysql: condition: service_healthy # 示例命令:生成迁移计划 command: > schema plan --url "mysql://root:rootpass@mysql:3306/app_db" -f /schema/schema.hcl
启动服务并执行命令:
bashdocker-compose up
| 参数/挂载项 | 说明 |
|---|---|
--url | 数据库连接串,格式为 <driver>://<user>:<password>@<host>:<port>/<db> |
-f, --file | 指定 schema 文件路径(HCL/SQL),支持容器内路径(需通过 -v 挂载本地文件) |
--dir | 迁移文件目录路径(版本化工作流),需挂载本地目录至容器内路径 |
-v <local>:<container> | 挂载本地目录至容器,用于共享 schema 文件、迁移文件等 |

manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务