使用专用 Docker 注册表

创建专用 Docker 注册表的存档

若要从专用 Docker 注册表中提供拉取凭据,请创建 Docker 凭据的存档,然后将其添加为服务或 pod 定义中的 URI。在 DC/OS Enterprise 中,您还可以将 Docker 注册表凭据上传到 DC/OS 密钥存储库,并在服务或 pod 定义中进行引用。

将专用 Docker 注册表凭据引用为 URI

步骤 1:压缩 Docker 凭据

  1. 手动登录专用注册表。登录后会在主目录中创建 .docker 文件夹和 .docker/config.json 文件。
    1. docker login some.docker.host.com
    2. Username: foo
    3. Password:
    4. Email: foo@bar.com
  2. 压缩 .docker 文件夹及其内容。
    1. cd ~
    2. tar -czf docker.tar.gz .docker
  3. 验证两个文件都在存档中。
    1. tar -tvf ~/docker.tar.gz
    2. drwx——— root/root 0 2015-07-28 02:54 .docker/
    3. -rw———- root/root 114 2015-07-28 01:31 .docker/config.json
  4. 将存档文件放置在您的应用定义可访问的位置。
    1. cp docker.tar.gz /etc/
重要信息:所有会启动您应用的节点都必须能够访问 URI。可以将文件分发到所有节点的本地文件系统,例如,通过 RSYNC/SCP 分发,或将其存储在共享网络驱动器上,例如 Amazon S3。仔细考虑所选方法的安全影响。 ## 步骤 2:将 URI 路径添加到服务定义
  1. 将存档文件登录凭据的路径添加到服务定义。
    1. "fetch": [
    2. {
    3. "uri": "file:///etc/docker.tar.gz"
    4. }
    5. ]
    例如:
    1. {
    2. "id": "/some/name/or/id",
    3. "cpus": 1,
    4. "mem": 1024,
    5. "instances": 1,
    6. "container": {
    7. "type": "DOCKER",
    8. "docker": {
    9. "image": "some.docker.host.com/namespace/repo"
    10. }
    11. },
    12. "fetch": [
    13. {
    14. "uri": "file:///etc/docker.tar.gz"
    15. }
    16. ]
    17. }
    Docker 镜像现在将使用提供的安全凭证进行拉取。
# 引用密钥存储库中的专用 Docker 注册表凭据 Enterprise 按照以下步骤向 DC/OS Enterprise 密钥存储库 添加 Docker 注册表凭据,然后在服务定义中引用该密钥。 重要信息:此功能仅适用于通用容器运行时。如果需要使用 Docker Engine,请遵循上述 URI 说明。 ## 步骤 1:创建凭据文件
  1. 手动登录您的专用注册表。这会创建 ~/.docker 目录和 ~/.docker/config.json 文件。
    1. docker login some.docker.host.com
    2. Username: foo
    3. Password:
    4. Email: foo@bar.com
  2. 检查您是否有 ~/.docker/config.json 文件。
    1. ls ~/.docker
    2. config.json
    您的 config.json 文件应该是这样的,其中 auth 的值是基于 64 位编码的 username:password 字符串。
    1. {
    2. "auths": {
    3. "https://index.docker.io/v1/": {
    4. "auth": "XXXXX",
    5. "email": "<your-email>"
    6. }
    7. }
    8. }
    如果使用的是 Mac OS,就需要手动编码 username:password 字符串并修改您的 config.json ,以便与上面的片段匹配。使用 base64 为密钥对编码时,请务必省略后面的换行符:
    1. echo -n myuser@domain.com:hard-to-guess-password | base64
  3. 添加 config.json 文件到 DC/OS 密钥存储库。了解创建密钥的详细信息注意:自 DC/OS 版本 1.10.0 开始,您只能使用 DC/OS CLI 将文件添加到密钥存储库。
    1. dcos security secrets create file=config.json <path/to/secret>
    如果您打算遵循以下示例,请输入以下命令以添加密钥:
    1. dcos security secrets create file=config.json mesos-docker/pullConfig

步骤 2:为您的服务或 pod 定义添加密钥

对于服务

  1. secrets 参数中添加密钥位置,并在 docker.pullConfig 参数中引用密钥。 重要信息:此功能 获得通用容器运行时的支持:container.type 必须为 MESOS
    1. {
    2. "id": "/mesos-docker",
    3. "container": {
    4. "docker": {
    5. "image": "<your/private/image>",
    6. "pullConfig": {
    7. "secret": "pullConfigSecret"
    8. }
    9. },
    10. "type": "MESOS"
    11. },
    12. "secrets": {
    13. "pullConfigSecret": {
    14. "source": "/mesos-docker/pullConfig"
    15. }
    16. },
    17. "args": ["hello"],
    18. "cpus": 0.2,
    19. "mem": 16.0,
    20. "instances": 1
    21. }
  2. 将服务添加到 DC/OS。如果您使用上述示例,则 <svc-name>mesos-docker
    1. dcos marathon app add <svc-name>.json
    Docker 镜像现在将使用提供的安全凭证进行拉取。

对于 pod

  1. secrets 参数中添加密钥位置,并在 containers.image.pullConfig 参数中引用密钥。 重要信息:仅当 image.kind 设置为 DOCKER 时,才支持此功能。
    1. {
    2. "id":"/simple-pod",
    3. "containers":[
    4. {
    5. "name":"simpletask1",
    6. "exec":{
    7. "command":{
    8. "shell":"env && sleep 1000"
    9. }
    10. },
    11. "resources":{
    12. "cpus":0.1,
    13. "mem":32
    14. },
    15. "image":{
    16. "kind":"DOCKER",
    17. "id":"<your/private/image>",
    18. "pullConfig":{
    19. "secret":"pullConfigSecret"
    20. }
    21. }
    22. }
    23. ],
    24. "networks":[
    25. {
    26. "mode":"host"
    27. }
    28. ],
    29. "secrets":{
    30. "pullConfigSecret":{
    31. "source":"/pod/pullConfig"
    32. }
    33. }
    34. }
  2. 将 pod 添加到 DC/OS。如果您使用上述示例,则 <pod-name>simple-pod
    1. dcos marathon pod add <pod-name>.json
    Docker 镜像现在将使用提供的安全凭证进行拉取。
# 配置代理以使用 Docker 注册表的自定义证书 某些组织需要用户凭据和有效的安全套接字层 (SSL) 证书,才能授权访问 Docker 注册表。例如,某些注册表配置需要一个证书来加密客户端与注册表之间的通信,而用户凭据则确定在成功连接到注册表之后,谁可以访问注册表。 如果您的专用注册表使用证书来保证通信,则可以配置代理节点来授信您用来访问专用 Docker 注册表的证书。 要配置用于访问专用 Docker 注册表和 DC/OS UCR 的自定义证书,请完成以下步骤:
  1. 创建或标识要用作访问 Docker 注册表的可信证书的自定义证书。 您可以使用 OpenSSL、DC/OS Enterprise CLI 或其他程序生成公钥和私钥、证书请求以及加密的客户端和服务器证书。 创建或标识证书后,可以按照注册表提供程序提供的说明将注册表配置为使用此证书。
  2. 将证书下载或复制到每个代理的以下两个位置。
    1. /etc/docker/certs.d/<registry_name>:<registry_port>/ca.crt
    2. /var/lib/dcos/pki/tls/certs/<something>.crt
    对于每个代理上可信 CA 证书的路径,请将 <registry_name><registry_port> 替换为适合您的安装的特定注册表名称和端口号。 例如,如果要将 DC/OS ca.crt 证书配置为可信证书并且本地 Docker 注册表引用为 registry.mycompany.com:5000,则可以下载 ca.crt 文件的副本并使用类似如下的命令将其设置为受信任:
    1. sudo mkdir -p /etc/docker/certs.d/registry.mycompany.com:5000
    2. sudo cp /path/to/ca.crt etc/docker/certs.d/registry.mycompany.com:5000/ca.crt
    3. sudo cp /etc/docker/certs.d/registry.mycompany.com:5000/ca.crt /var/lib/dcos/pki/tls/certs/docker-registry-ca.crt
  3. 通过运行类似如下的命令为文件生成散列:
    1. cd /var/lib/dcos/pki/tls/certs/
    2. openssl x509 -hash -noout -in docker-registry-ca.crt
  4. Create a symbolic link from the trusted certificate to the /var/lib/dcos/pki/tls/certs directory on the public agent.
    1. sudo ln -s /var/lib/dcos/pki/tls/certs/docker-registry-ca.crt /var/lib/dcos/pki/tls/certs/<hash_number>.0
# Pushing a custom image to a private registry from a tarball If you asked your sales representative for an enterprise version of Marathon, you may have been given a Docker image in a .tar archive. Follow these steps to deploy it to your registry: ## Step 1: Import in the local machine
  1. Load the tarball into your local Docker client, passing the path to your custom tarball. For example, marathon-dcos-ee.<version>.tar:
    1. docker load -i marathon-dcos-ee.<version>.tar
    Tip: You can view the Marathon image with this command.
    1. docker images
    You should see output similar to this:
    1. REPOSITORY TAG IMAGE ID CREATED SIZE
    2. mesosphere/marathon-dcos-ee 1.4.0-RC4_1.9.4 d1ffa68a50c0 3 months ago 926.4 MB

Step 2: Push the image to the repository

  1. Re-tag the file to match the repository that you are using in your private Docker registry:
    1. docker tag \
    2. mesosphere/marathon-dcos-ee:<mesosphere-tag> \
    3. <your-repo>/marathon-dcos-ee:<your-tag>
    Where:
    • <mesosphere-tag> is the tag of the image from Mesosphere. Typically, this will match the version number in the filename.
    • <your-repo> is the name of the private repository that you want to store the image in.
    • <your-tag> is the tag for the image. It is recommended that you use the same tag as the Mesosphere image.
  2. Push the new image to your private Docker registry:
    1. docker push <your-repo>/marathon-dcos-ee:<your-tag>