Issue
I know there has been a few questions posted on similar issues already but unfortunately I still can't manage to get the following command working :
$sudo docker run hello-world
Unable to find image 'hello-world:latest' locally docker: Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp 52.54.216.153:443: getsockopt: connection refused. See 'docker run --help'.
I am using CentOS7 virtual machine on VirtualBox with HTTP/HTTPS/FTP proxy settings configured at system level. This proxy configuration has been working fine for Chrome and other applications.
After browsing this forum, I tried to create explicit proxy settings for the Docker application by:
creating a ~/.docker/config.json file as mentioned at https://docs.docker.com/network/proxy/ and then do "systemctl restart docker"
creating a /etc/systemd/system/docker.service.d/http-proxy.conf and then do "systemctl daemon-reload" and "systemctl restart docker"
Here is the version of Docker on my virtual machine:
$sudo docker version
Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:20:16 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.1-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:23:58 2018
OS/Arch: linux/amd64
Experimental: false
$curl -v https://registry-1.docker.io/v2/
* About to connect() to proxy XXX port 8012 (#0)
...
>
< HTTP/1.1 200 Connection established
<
* Proxy replied OK to CONNECT request
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
* subject: CN=*.docker.io
* start date: Aug 02 00:00:00 2017 GMT
* expire date: Sep 02 12:00:00 2018 GMT
* common name: *.docker.io
* issuer: CN=Amazon,OU=Server CA 1B,O=Amazon,C=US
> GET /v2/ HTTP/1.1
> User-Agent: curl/7.29.0
> Host: registry-1.docker.io
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< Www-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io"
< Date: Fri, 08 Jun 2018 16:00:17 GMT
< Content-Length: 87
< Strict-Transport-Security: max-age=31536000
<
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":null}]}
* Connection #0 to host XXX left intact
$curl -v https://54.152.209.167
...
...
< HTTP/1.1 200 Connection established
<
* Proxy replied OK to CONNECT request
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* Server certificate:
* subject: CN=*.docker.io
* start date: Aug 02 00:00:00 2017 GMT
* expire date: Sep 02 12:00:00 2018 GMT
* common name: *.docker.io
* issuer: CN=Amazon,OU=Server CA 1B,O=Amazon,C=US
* NSS error -12276 (SSL_ERROR_BAD_CERT_DOMAIN)
* Unable to communicate securely with peer: requested domain name does not match the server's certificate.
* Closing connection 0
curl: (51) Unable to communicate securely with peer: requested domain name does not match the server's certificate.
Solution
As mentioned in https://docs.docker.com/config/daemon/systemd/#httphttps-proxy, the following commands solved my problem. It was kind of lost in the doc, IMO.
$ sudo mkdir -p /etc/systemd/system/docker.service.d
vi /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="http://IP:PORT/"
vi /etc/systemd/system/docker.service.d/https-proxy.conf
[Service]
Environment="http://IP:PORT/"
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://"http://IP:PORT/"
Answered By - Pierric