Docker 配置 Neuxs 仓库 | Nuget 配置 Docker 仓库

2021年8月11日 1680点热度 0人点赞 0条评论
内容纲要

Docker

如果使用 Nexus 配置 Docker 私有仓库,但是 Docker 不配置好地址,那么拉取镜像时会提示:

Error response from daemon: Get https://192.168.0.111:666/v2/: http: server gave HTTP response to HTTPS client

首先在 Nexus 上配置好 Docker 仓库。 例如下图,其端口是 8082。
file

因为使用的是 HTTP、HTTPS ,因此需要配置修改参数,打开 /etc/docker/daemon.json 文件,加上 insecure-registries,例如:

{
"registry-mirrors": [
    "https://registry.docker-cn.com"
  ]
"insecure-registries": ["192.168.0.111:8282","192.158.0.111:8083"]
}

一定要加上 8083,因为需要 https。

然后重启 Docker:

systemctl daemon-reload
systemctl restart docker

然后登录 Nexus 的 Docker 仓库:

docker login 192.168.0.111:8082
Username: viwer
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

Nuget

如果在 VS,那么直接在 Nuget 设置 添加即可,然后选择依赖时,会要求输入账号密码。

如果要在 CI/CD 中,使用私有 Nuget ,则颇为麻烦。

我们可以增加一个 nuget.config 配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key="nuget" value="https://api.nuget.org/v3/index.json" />
    <add key="dahui" value="http://192.168.0.111:8181/repository/nuget" />
  </packageSources>
  <packageSourceCredentials>
    <dahui>
        <add key="Username" value="你的用户名" />
        <add key="ClearTextPassword" value="你的用户名" />
    </dahui>
</packageSourceCredentials>
</configuration>

密码可以使用非明文,详细请参考
https://docs.microsoft.com/zh-cn/nuget/consume-packages/configuring-nuget-behavior
https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file

然后在编译的时候,将 nuget.config 复制到 .sln 文件相同的目录下即可。

痴者工良

高级程序员劝退师

文章评论