如何通过代理使用 "docker login"?
How to use "docker login" with a proxy?
我正在尝试 运行 docker login
,但出现以下错误:
Error response from daemon: Get "https://[removed_id_for_Whosebug].dkr.ecr.us-east-1.amazonaws.com/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
我的 ~/.bash.rc
文件中有以下内容:
export HTTP_PROXY="http://192.168.1.1:8080"
export HTTPS_PROXY="http://192.168.1.1:8080"
export https_proxy="http://192.168.1.1:8080"
export https_proxy="http://192.168.1.1:8080"
export ftp_proxy="http://192.168.1.1:8080"
export no_proxy="localhost,127.0.0.1,::1"
如果我 运行 curl https://www.google.com
那么我可以获得有效的响应,确认这些设置有效。如果我删除这些环境变量,那么我的 curl
命令将不再有效,所以我很确定它从环境变量的角度来看配置正确。
根据 ,您可以在 运行ning docker login
时将代理选项传递到命令行;但是,我试过了,结果是一样的。请参阅以下示例:
root@my-host:~/.docker# HTTPS_PROXY=http://192.168.1.1:8080 aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $(aws sts get-caller-identity --output text --query 'Account').dkr.ecr.us-east-1.amazonaws.com >/dev/null
Error response from daemon: Get "https://[removed_for_stack_overflow].dkr.ecr.us-east-1.amazonaws.com/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
我尝试将代理设置更改为出现在 docker login
之前而不是 aws
,尝试使用 HTTP_PROXY
而不是 HTTPS_PROXY
,但仍然没有成功。指定代理选项的顺序似乎无关紧要。
我还有一个名为 ~/.docker/config.json
的文件,其中包含以下代理信息:
{
"proxies":
{
"default":
{
"httpProxy": "http://192.168.1.1:8080",
"httpsProxy": "http://192.168.1.1:8080"
}
}
}
即使使用此设置,docker 登录似乎仍未正常工作并提供相同的结果。
为docker守护进程配置代理的正确方法已记录here,我提取了一些内容供您参考:
Create a systemd drop-in directory for the docker service:
sudo mkdir -p /etc/systemd/system/docker.service.d
Create a file named /etc/systemd/system/docker.service.d/http-proxy.conf
that adds the HTTP_PROXY/HTTPS_PROXY
environment variable:
Config example:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80"
Environment="HTTPS_PROXY=https://proxy.example.com:443"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"
Flush changes and restart Docker
sudo systemctl daemon-reload
sudo systemctl restart docker
Verify that the configuration has been loaded and matches the changes you made, for example:
sudo systemctl show --property=Environment docker
我正在尝试 运行 docker login
,但出现以下错误:
Error response from daemon: Get "https://[removed_id_for_Whosebug].dkr.ecr.us-east-1.amazonaws.com/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
我的 ~/.bash.rc
文件中有以下内容:
export HTTP_PROXY="http://192.168.1.1:8080"
export HTTPS_PROXY="http://192.168.1.1:8080"
export https_proxy="http://192.168.1.1:8080"
export https_proxy="http://192.168.1.1:8080"
export ftp_proxy="http://192.168.1.1:8080"
export no_proxy="localhost,127.0.0.1,::1"
如果我 运行 curl https://www.google.com
那么我可以获得有效的响应,确认这些设置有效。如果我删除这些环境变量,那么我的 curl
命令将不再有效,所以我很确定它从环境变量的角度来看配置正确。
根据 docker login
时将代理选项传递到命令行;但是,我试过了,结果是一样的。请参阅以下示例:
root@my-host:~/.docker# HTTPS_PROXY=http://192.168.1.1:8080 aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $(aws sts get-caller-identity --output text --query 'Account').dkr.ecr.us-east-1.amazonaws.com >/dev/null
Error response from daemon: Get "https://[removed_for_stack_overflow].dkr.ecr.us-east-1.amazonaws.com/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
我尝试将代理设置更改为出现在 docker login
之前而不是 aws
,尝试使用 HTTP_PROXY
而不是 HTTPS_PROXY
,但仍然没有成功。指定代理选项的顺序似乎无关紧要。
我还有一个名为 ~/.docker/config.json
的文件,其中包含以下代理信息:
{
"proxies":
{
"default":
{
"httpProxy": "http://192.168.1.1:8080",
"httpsProxy": "http://192.168.1.1:8080"
}
}
}
即使使用此设置,docker 登录似乎仍未正常工作并提供相同的结果。
为docker守护进程配置代理的正确方法已记录here,我提取了一些内容供您参考:
Create a systemd drop-in directory for the docker service:
sudo mkdir -p /etc/systemd/system/docker.service.d
Create a file named
/etc/systemd/system/docker.service.d/http-proxy.conf
that adds theHTTP_PROXY/HTTPS_PROXY
environment variable:Config example:
[Service] Environment="HTTP_PROXY=http://proxy.example.com:80" Environment="HTTPS_PROXY=https://proxy.example.com:443" Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"
Flush changes and restart Docker
sudo systemctl daemon-reload sudo systemctl restart docker
Verify that the configuration has been loaded and matches the changes you made, for example:
sudo systemctl show --property=Environment docker