
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
自动更新 DNS 解析到本机 IP 地址,支持 IPv4 和 IPv6,本地(内网)IP 和公网 IP。
https://img.shields.io/github/v/release/NewFuture/DDNS?&logo=github&style=flatten](https://github.com/NewFuture/DDNS/releases/latest) https://img.shields.io/pypi/v/ddns.svg?label=ddns&logo=pypi&style=flatten](https://pypi.org/project/ddns/) https://img.shields.io/docker/v/newfuture/ddns?label=newfuture/ddns&logo=docker&&sort=semver&style=flatten](https://hub.docker.com/r/newfuture/ddns) https://github.com/NewFuture/DDNS/actions/workflows/build.yml/badge.svg?event=push](https://github.com/NewFuture/DDNS/actions/workflows/build.yml) https://github.com/NewFuture/DDNS/actions/workflows/publish.yml/badge.svg](https://github.com/NewFuture/DDNS/actions/workflows/publish.yml)
DDNS是一个轻量级Docker镜像,用于自动将DNS记录更新到本机当前IP地址。支持IPv4/IPv6、本地(内网)和公网IP,兼容多种DNS服务商,包括dnspod、阿里DNS、CloudFlare、华为云、DNSCOM等。该镜像设计用于在家庭网络、小型服务器或任何需要动态IP地址管理的场景中,保持域名解析与当前IP地址同步。
DDNS镜像版本(Docker Tag):
latest: 最新稳定版(默认)next: 下一个测试版本edge: 最新开发版,不稳定(master分支)bash# 拉取最新稳定版 docker pull docker.xuanyuan.run/newfuture/ddns:latest # 或直接使用 docker pull docker.xuanyuan.run/newfuture/ddns
指定特定版本:
bashdocker pull docker.xuanyuan.run/newfuture/ddns:v4.0.0
镜像会同步发布到以下源:
docker.io/newfuture/ddnsghcr.io/newfuture/ddns使用GitHub源:
bashdocker pull ***-ghcr.xuanyuan.run/newfuture/ddns
DDNS Docker镜像支持三种配置方式:命令行、环境变量和配置文件。
使用命令行参数 (CLI)
当设置命令行参数时,容器将直接运行DDNS程序,不会启用定时任务。适合一次性运行或调试。
bash# 查看帮助 docker run --rm docker.xuanyuan.run/newfuture/ddns -h # 基本使用示例 docker run --rm -v /local/config/:/ddns/ --network=host docker.xuanyuan.run/newfuture/ddns \ --dns=dnspod \ --id=12345 \ --token=mytokenkey \ --ipv4=www.example.com \ --ipv4=ipv4.example.com \ --index4 public \ --index4 0 # 启用调试模式 docker run --rm -v /local/config/:/ddns/ --network=host docker.xuanyuan.run/newfuture/ddns \ --dns=dnspod \ --id=12345 \ --token=mytokenkey \ --ipv4=www.example.com \ --debug
使用环境变量 (ENV)
环境变量需加上DDNS前缀,推荐全大写。数组类型需要使用JSON格式或者单引号包裹。
bashdocker run -d \ -e DDNS_DNS=dnspod \ -e DDNS_ID=12345 \ -e DDNS_TOKEN=mytokenkey \ -e DDNS_IPV4=example.com,www.example.com \ -e DDNS_INDEX4=['public',0] \ --network host \ --name ddns \ docker.xuanyuan.run/newfuture/ddns
使用环境变量文件:
bashdocker run -d --env-file .env --network host --name ddns docker.xuanyuan.run/newfuture/ddns
支持的主要环境变量:
| 环境变量 | 描述 | 示例 |
|---|---|---|
| DDNS_DNS | DNS服务商 | dnspod |
| DDNS_ID | API访问ID | *** |
| DDNS_TOKEN | API访问令牌 | mytokenkey |
| DDNS_IPV4 | IPv4域名列表 | example.com,[***] |
| DDNS_IPV6 | IPv6域名列表 | ipv6.example.com |
| DDNS_INDEX4 | IPv4地址获取方式 | ['public',0] |
| DDNS_INDEX6 | IPv6地址获取方式 | ['public',0] |
| DDNS_LOG_LEVEL | 日志级别 | WARNING |
| DDNS_PROXY | HTTP代理 | [***] |
使用配置文件
Docker容器内的工作目录是/ddns/,默认配置文件路径为容器内的/ddns/config.json。
bashdocker run -d \ -v /host/config/:/ddns/ \ --network host \ --name ddns \ docker.xuanyuan.run/newfuture/ddns
其中/host/config/是您本地包含config.json的目录。基本的config.json格式示例:
json{ "dns": "dnspod", "id": "12345", "token": "mytokenkey", "ipv4": ["example.com", "www.example.com"], "index4": ["public", 0] }
host网络模式
使用--network host让容器直接使用宿主机网络,可正确获取宿主机IP地址。
bashdocker run -d \ -e DDNS_DNS=dnspod \ -e DDNS_ID=12345 \ -e DDNS_TOKEN=mytokenkey \ -e DDNS_IPV4=example.com \ --network host \ --name ddns \ docker.xuanyuan.run/newfuture/ddns
bridge网络模式(默认)
容器使用独立网络栈,需使用public模式获取公网IP:
bashdocker run -d \ -e DDNS_DNS=dnspod \ -e DDNS_ID=12345 \ -e DDNS_TOKEN=mytokenkey \ -e DDNS_IPV4=example.com \ -e DDNS_INDEX4=public \ --name ddns \ docker.xuanyuan.run/newfuture/ddns
多域名配置
环境变量方式配置多域名:
bashdocker run -d \ -e DDNS_DNS=dnspod \ -e DDNS_ID=12345 \ -e DDNS_TOKEN=mytokenkey \ -e DDNS_IPV4='["example.com", "www.example.com", "sub.example.com"]' \ --network host \ --name ddns \ docker.xuanyuan.run/newfuture/ddns
命令行参数方式配置多域名:
bashdocker run --rm --network host docker.xuanyuan.run/newfuture/ddns \ --dns dnspod \ --id 12345 \ --token mytokenkey \ --ipv4 ipv4.example.com \ --ipv4 www.example.com
启用IPv6支持
/etc/docker/daemon.json:json{ "ipv6": true, "fixed-cidr-v6": "fd00::/80" }
bashsudo systemctl restart docker
bashdocker run -d \ --network host \ -e DDNS_DNS=dnspod \ -e DDNS_ID=12345 \ -e DDNS_TOKEN=mytokenkey \ -e DDNS_IPV6=example.com \ --name ddns \ docker.xuanyuan.run/newfuture/ddns
基本环境变量配置
创建docker-compose.yml文件:
yamlversion: "3" services: ddns: image: docker.xuanyuan.run/newfuture/ddns:latest restart: always network_mode: host environment: - DDNS_DNS=dnspod - DDNS_ID=12345 - DDNS_TOKEN=mytokenkey - DDNS_IPV4=example.com,www.example.com - DDNS_INDEX4=['public','url:https://api.ipify.org'] - DDNS_LOG_LEVEL=WARNING
使用配置文件
yamlversion: "3" services: ddns: image: docker.xuanyuan.run/newfuture/ddns:latest restart: always network_mode: host volumes: - ./config:/ddns
运行Docker Compose:
bashdocker-compose up -d
如需在容器中添加其他工具或自定义环境,可基于官方镜像创建Dockerfile:
dockerfileFROM docker.xuanyuan.run/newfuture/ddns:latest # 安装额外工具 RUN apk add --no-cache curl # 添加自定义脚本 COPY custom-script.sh /bin/ RUN chmod +x /bin/custom-script.sh # 可选:覆盖默认入口点 # ENTRYPOINT ["/bin/custom-script.sh"]
问题:DDNS无法正确获取主机IP
解决方案:
--network host网络模式-e DDNS_INDEX4=public强制使用公网API获取IP问题:容器运行但不自动更新DNS
解决方案:
docker logs ddnsdocker ps -adocker exec ddns /bin/ddns问题:容器启动后立即退出
解决方案:
docker run -it --rm newfuture/ddns问题:容器无法连接到DNS服务商API
解决方案:
docker exec ddns ping api.dnspod.cn-e DDNS_PROXY=http://proxy:port您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务