美文网首页
CentOS7下docker安装,代理设置,链接超时错误解决

CentOS7下docker安装,代理设置,链接超时错误解决

作者: 韩小禹 | 来源:发表于2019-04-02 14:58 被阅读0次

    安装docker

    # 建议安装之前先将yum源更换为阿里或者163的源
    yum install -y docker
    
    # 启动docker
    systemctl start docker
    
    # 确认dock安装并运行
    docker info
    

    测试拉取镜像

    • 拉取测试hello-world镜像
    # 执行命令
    docker run hello-world
    
    # 报错,我这里报错的原因是由于公司网络需要设置代理才可以上网,所以需要给docker设置网络代理
    Unable to find image 'hello-world:latest' locally
    Trying to pull repository docker.io/library/hello-world ... 
    /usr/bin/docker-current: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
    See '/usr/bin/docker-current run --help'.
    
    • 设置docker网络代理
    # 在路径 etc/systemd/system/ 中创建文件夹 docker.service.d ,并创建一个 http-proxy.conf 文件。
    # 写入内容
    [Service]
    Environment="HTTP_PROXY=http://[proxy-addr]:[proxy-port]/" "HTTPS_PROXY=http://[proxy-addr]:[proxy-port]/" "NO_PROXY=localhost,127.0.0.1"
    
    # 注意,这个的HTTPS_PROXY也要设置为和HTTP_PROXY,否则会另外一种错误,如下所示
    
    • 重新执行命令 docker run hello-world ,发现报错。
    [root@localhost /]# docker run hello-world
    Unable to find image 'hello-world:latest' locally
    Trying to pull repository docker.io/library/hello-world ... 
    /usr/bin/docker-current: Get https://registry-1.docker.io/v2/: proxyconnect tcp: tls: oversized record received with length 20527.
    See '/usr/bin/docker-current run --help'.
    
    
    • 重启docker
    # 更新配置
    systemctl daemon-reload
    
    # 重启docker
    systemctl restart docker
    
    • 查看代理配置
    systemctl show --property=Environment docker
    
    • 测试
    docker run hello-world
    
    • 测试结果


      QQ截图20190402150202.png

    相关文章

      网友评论

          本文标题:CentOS7下docker安装,代理设置,链接超时错误解决

          本文链接:https://www.haomeiwen.com/subject/igovbqtx.html