使用环境变量进行 Docker 分发中间件配置

Using Environment Variables for Docker Distribution Middleware Configuration

根据 Docker docs,您可以通过以下任一方式配置 docker 注册表映像:

  1. 构建 yaml 文件并挂载它。
  2. 传递环境变量。

而 2. 方法说 in the docs:

To override a configuration option, create an environment variable named REGISTRY_variable where variable is the name of the configuration option and the _ (underscore) represents indention levels. For example, you can configure the rootdirectory of the filesystem storage backend:

storage:
  filesystem:
    rootdirectory: /var/lib/registry

To override this value, set an environment variable like this:

REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/somewhere

This variable overrides the /var/lib/registry value to the /somewhere directory.

虽然有一种情况我无法让它工作,但它工作得很好,那就是中间件配置。

我想通过 ENV vars 这个设置

middleware:
  storage:
    - name: cloudfront
      options:
        baseurl: https://my.cloudfronted.domain.com/
        privatekey: /path/to/pem
        keypairid: cloudfrontkeypairid
        awsregion: us-east-1, use-east-2

我试过传递以下环境变量名称:

- REGISTRY_MIDDLEWARE_STORAGE_CLOUDFRONT_BASEURL
- REGISTRY_MIDDLEWARE_STORAGE_0_OPTIONS_BASEURL

但所有这些似乎都被忽略了,我什至试图错误地编写配置(因为这会触发验证错误,我将能够在输出中看到它),但没有成功。

我试过这个:

# file.env
REGISTRY_LOG_LEVEL="debug"
REGISTRY_HTTP_ADDR=":5000"
REGISTRY_HTTP_SECRET="lol"

REGISTRY_STORAGE_S3_ENCRYPT=true
REGISTRY_STORAGE_S3_ROOTDIRECTORY=/REG
REGISTRY_STORAGE_S3_BUCKET="development-bucket-test"
REGISTRY_STORAGE_S3_ACCESSKEY="AAAAAAAA"
REGISTRY_STORAGE_S3_SECRETKEY="BBBBBBB"
REGISTRY_STORAGE_S3_REGION="XX-TTT-X"

REGISTRY_MIDDLEWARE_STORAGE_CLOUDFRONT_BASEURL="tp:/examplezzz.com"
REGISTRY_MIDDLEWARE_STORAGE_CLOUDFRONT_BASEUL="tp:/examplezzz.com"

REGISTRY_MIDDLEWARE_STORAGE_0_NAME=cloudfront
REGISTRY_MIDDLEWARE_STORAGE_0_OPTIONS_BASEUL="tp:/examplezzz.com"
REGISTRY_MIDDLEWARE_STORAGE_0_OPTIONS__AWSRGION="tp:/examplezzz.com"
# run the registry with
docker run --rm -it -p 5000:5000 --env-file file.env registry:2.7.1 sh -c 'echo "version: 0.1" > /a.conf; registry serve /a.conf'

P.S.: /a.conf 用于强制空配置

我是不是遗漏了什么,或者这个设置只能通过配置文件实现吗?

我继续自己修改 docker 发行版的源代码,并通过传递使其接受配置:

REGISTRY_MIDDLEWARE_STORAGE="[{name: cloudfront, options: {baseurl: 'someurl', privatekey: 'somefile', keypairid: 'somestring'}}]"