使用专用 Docker 注册表
创建专用 Docker 注册表的存档
将专用 Docker 注册表凭据引用为 URI
-
手动登录专用注册表。登录后会在主目录中创建 文件夹和
.docker/config.json
文件。 -
压缩
.docker
文件夹及其内容。cd ~
tar -czf docker.tar.gz .docker
-
验证两个文件都在存档中。
tar -tvf ~/docker.tar.gz
drwx——— root/root 0 2015-07-28 02:54 .docker/
-rw———- root/root 114 2015-07-28 01:31 .docker/config.json
-
将存档文件放置在您的应用定义可访问的位置。
cp docker.tar.gz /etc/
-
将存档文件登录凭据的路径添加到服务定义。
例如:"fetch": [
{
"uri": "file:///etc/docker.tar.gz"
}
]
Docker 镜像现在将使用提供的安全凭证进行拉取。{
"id": "/some/name/or/id",
"cpus": 1,
"mem": 1024,
"instances": 1,
"container": {
"type": "DOCKER",
"docker": {
"image": "some.docker.host.com/namespace/repo"
}
},
"fetch": [
{
"uri": "file:///etc/docker.tar.gz"
}
]
}
-
手动登录您的专用注册表。这会创建
~/.docker
目录和~/.docker/config.json
文件。docker login some.docker.host.com
Username: foo
Password:
-
检查您是否有
~/.docker/config.json
文件。
您的ls ~/.docker
config.json
config.json
文件应该是这样的,其中auth
的值是基于 64 位编码的username:password
字符串。 如果使用的是 Mac OS,就需要手动编码username:password
字符串并修改您的config.json
,以便与上面的片段匹配。使用 base64 为密钥对编码时,请务必省略后面的换行符:echo -n myuser@domain.com:hard-to-guess-password | base64
-
添加 文件到 DC/OS 密钥存储库。。
注意:自 DC/OS 版本 1.10.0 开始,您只能使用 DC/OS CLI 将文件添加到密钥存储库。
如果您打算遵循以下示例,请输入以下命令以添加密钥:dcos security secrets create —file=config.json <path/to/secret>
dcos security secrets create —file=config.json mesos-docker/pullConfig
-
在
secrets
参数中添加密钥位置,并在docker.pullConfig
参数中引用密钥。 重要信息:此功能 仅 获得通用容器运行时的支持:container.type
必须为MESOS
。{
"id": "/mesos-docker",
"container": {
"docker": {
"image": "<your/private/image>",
"pullConfig": {
"secret": "pullConfigSecret"
}
},
"type": "MESOS"
},
"secrets": {
"pullConfigSecret": {
"source": "/mesos-docker/pullConfig"
}
},
"args": ["hello"],
"cpus": 0.2,
"mem": 16.0,
"instances": 1
}
-
将服务添加到 DC/OS。如果您使用上述示例,则
<svc-name>
为mesos-docker
。
Docker 镜像现在将使用提供的安全凭证进行拉取。dcos marathon app add <svc-name>.json
对于 pod
-
在
secrets
参数中添加密钥位置,并在containers.image.pullConfig
参数中引用密钥。 重要信息:仅当image.kind
设置为DOCKER
时,才支持此功能。{
"id":"/simple-pod",
"containers":[
{
"name":"simpletask1",
"exec":{
"command":{
"shell":"env && sleep 1000"
}
},
"resources":{
"cpus":0.1,
"image":{
"kind":"DOCKER",
"id":"<your/private/image>",
"pullConfig":{
"secret":"pullConfigSecret"
}
}
}
],
"networks":[
{
"mode":"host"
}
],
"secrets":{
"pullConfigSecret":{
"source":"/pod/pullConfig"
}
}
}
-
将 pod 添加到 DC/OS。如果您使用上述示例,则
<pod-name>
为simple-pod
。
Docker 镜像现在将使用提供的安全凭证进行拉取。dcos marathon pod add <pod-name>.json
- 创建或标识要用作访问 Docker 注册表的可信证书的自定义证书。 您可以使用 OpenSSL、DC/OS Enterprise CLI 或其他程序生成公钥和私钥、证书请求以及加密的客户端和服务器证书。 创建或标识证书后,可以按照注册表提供程序提供的说明将注册表配置为使用此证书。
-
将证书下载或复制到每个代理的以下两个位置。
对于每个代理上可信 CA 证书的路径,请将
<registry_name>
和<registry_port>
替换为适合您的安装的特定注册表名称和端口号。 例如,如果要将 DC/OSca.crt
证书配置为可信证书并且本地 Docker 注册表引用为registry.mycompany.com:5000
,则可以下载ca.crt
文件的副本并使用类似如下的命令将其设置为受信任:sudo mkdir -p /etc/docker/certs.d/registry.mycompany.com:5000
sudo cp /path/to/ca.crt etc/docker/certs.d/registry.mycompany.com:5000/ca.crt
sudo cp /etc/docker/certs.d/registry.mycompany.com:5000/ca.crt /var/lib/dcos/pki/tls/certs/docker-registry-ca.crt
-
通过运行类似如下的命令为文件生成散列:
cd /var/lib/dcos/pki/tls/certs/
openssl x509 -hash -noout -in docker-registry-ca.crt
-
Create a symbolic link from the trusted certificate to the
/var/lib/dcos/pki/tls/certs
directory on the public agent.sudo ln -s /var/lib/dcos/pki/tls/certs/docker-registry-ca.crt /var/lib/dcos/pki/tls/certs/<hash_number>.0
.tar
archive. Follow these steps to deploy it to your registry:
## Step 1: Import in the local machine
-
Load the tarball into your local Docker client, passing the path to your custom tarball. For example,
marathon-dcos-ee.<version>.tar
:
Tip: You can view the Marathon image with this command.docker load -i marathon-dcos-ee.<version>.tar
You should see output similar to this:docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mesosphere/marathon-dcos-ee 1.4.0-RC4_1.9.4 d1ffa68a50c0 3 months ago 926.4 MB
-
Re-tag the file to match the repository that you are using in your private Docker registry:
Where:docker tag \
mesosphere/marathon-dcos-ee:<mesosphere-tag> \
<your-repo>/marathon-dcos-ee:<your-tag>
<mesosphere-tag>
is the tag of the image from Mesosphere. Typically, this will match the version number in the filename.- 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.
- Push the new image to your private Docker registry: