使用容器镜像

使用存储在 Drycc 容器注册表中的容器镜像部署应用程序。

Drycc 支持通过现有的 [Docker 镜像][] 部署应用程序。 这对于将 Drycc 集成到基于 Docker 的 CI/CD 流水线中很有用。

准备应用程序

首先克隆示例应用程序:

$ git clone https://github.com/drycc/example-dockerfile-http.git
$ cd example-dockerfile-http

接下来使用您的本地 docker 客户端构建镜像并推送 到 DockerHub

$ docker build -t <username>/example-dockerfile-http .
$ docker push <username>/example-dockerfile-http

Docker 镜像要求

为了部署 Docker 镜像,它们必须符合以下要求:

  • Dockerfile 必须使用 EXPOSE 指令来公开恰好一个端口。
  • 该端口必须监听 HTTP 连接。
  • Dockerfile 必须使用 CMD 指令来定义将在容器内运行的默认进程。
  • Docker 镜像必须包含 bash 来运行进程。

创建应用程序

使用 drycc createcontroller 上创建应用程序。

$ mkdir -p /tmp/example-dockerfile-http && cd /tmp/example-dockerfile-http
$ drycc create example-dockerfile-http --no-remote
Creating application... done, created example-dockerfile-http

部署应用程序

使用 drycc pullDockerHub 或 公共注册表部署您的应用程序。

$ drycc pull <username>/example-dockerfile-http:latest
Creating build...  done, v2

$ curl -s http://example-dockerfile-http.local3.dryccapp.com
Powered by Drycc

因为您正在部署 Docker 镜像,web 进程类型在首次部署时自动扩展到 1。

使用 drycc scale web=3web 进程增加到 3,例如。直接扩展进程类型会更改运行该进程的 容器 数量。

私有注册表

要从私有注册表或私有仓库部署 Docker 镜像,请使用 drycc registry 将凭据附加到您的应用程序。这些凭据与您在私有注册表运行 docker login 时使用的凭据相同。

要部署私有 Docker 镜像,请执行以下步骤:

  • 收集注册表的用户名和密码,例如 Quay.io Robot AccountGCR.io Long Lived Token
  • 运行 drycc registry set <the-user> <secret> -a <application-name>
  • 现在像往常一样对私有注册表中的镜像执行 drycc pull

当使用 GCR.io Long Lived Token 时,JSON blob 必须首先使用 jq 等工具压缩,然后在 drycc registry set 的密码字段中使用。对于用户名,使用 _json_key。例如:

drycc registry set _json_key "$(cat google_cloud_cred.json | jq -c .)"

当使用私有注册表时,Docker 镜像不再通过 Drycc Workflow Controller 拉取到 Drycc 内部注册表,而是由 Kubernetes 管理。这将提高安全性和整体速度, 但是应用程序 port 信息无法再被发现。相反,应用程序 port 信息可以通过 drycc config set PORT=80 在设置注册表信息之前设置。


最后修改 2025.10.09: feat(i18n): add chinese lang (2c1052a)