核心步骤

1. 创建 Docker 配置文件密钥

首先,你需要在 Drone 仓库设置中创建一个 Secret,内容必须是 Docker 的 config.json 格式:

{
    "auths": {
        "docker.io": {
            "auth": "4452D71687B6BC2C9389C3..."
        }
    }
}

注意:

auth 值是你的 Docker 用户名和密码的 Base64 编码(格式:username:password)
可以配置多个镜像仓库(如 docker.io、gcr.io、registry.internal.company.com 等)

2. 生成 auth token

在 Linux/macOS 上生成 auth token:

echo -n "your_username:your_password" | base64

3. 在 .drone.yml 中配置

在你的 Pipeline 配置中,使用 image_pull_secrets 属性指定密钥名称:

steps:
- name: build
  image: registry.internal.company.com/golang:1.12
  commands:
  - go build
  - go test

image_pull_secrets:
- dockerconfig  # 这里填写你在 Drone 中创建的 Secret 名称

总结:核心就是创建包含 Docker 认证信息的 Secret,然后在配置文件中引用它即可。

标签: none

评论已关闭