centos7 docker使用https_proxy 代理配置

背景:
内网的centos主机不能上网,通过同网段的windows设置代理上网,yum.conf配置http代理是可以的,但是docker无法拉取镜像

处理办法:
如果是centos6版本只需要在/etc/sysconfig/docker 配置文件里面增加配置即可
centos7 使用systemd 来管理进程环境,我们需要如下配置来应用https_proxy

创建目录

mkdir /etc/systemd/system/docker.service.d
创建文件
vim /etc/systemd/system/docker.service.d/http-proxy.conf

配置http-proxy.conf文件增加以下内容

[Service]
Environment=”HTTP_PROXY=http://10.11.0.148:808″
daemon重新reload 并重启docker

systemctl daemon-reload
systemctl restart docker
检查变量是否加载

systemctl show docker –property Environment

2.curl命令添加http和https代理
默认使用curl命令在代理模式下是无法使用的,需要在bash命令行下添加代理

export http_proxy=http://10.11.0.148:808
export https_proxy=https://10.11.0.148:808

[root@node1 hello-world]

# curl -vv http://www.baidu.com

  • About to connect() to proxy 10.11.0.148 port 808 (#0)
  • Trying 10.11.0.148…
  • Connected to 10.11.0.148 (10.11.0.148) port 808 (#0)

GET http://www.baidu.com/ HTTP/1.1
User-Agent: curl/7.29.0
Host: www.baidu.com
Accept: /
Proxy-Connection: Keep-Alive

< HTTP/1.1 200 OK < Accept-Ranges: bytes < Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform < Connection: Keep-Alive < Content-Length: 2381 < Content-Type: text/html < Date: Tue, 12 Jun 2018 01:14:04 GMT < Etag: “588604dd-94d” < Last-Modified: Mon, 23 Jan 2017 13:27:57 GMT < Pragma: no-cache < Server: bfe/1.0.8.18 < Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/ <

关于百度 About Baidu

©2017 Baidu 使用百度前必读  意见反馈 京ICP证030173号 

  • Connection #0 to host 10.11.0.148 left intact

[root@node1 ~]

# curl –head https://www.baidu.com
HTTP/1.1 200 Connection established
Proxy-agent: CCProxy

HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 277
Content-Type: text/html
Date: Tue, 12 Jun 2018 05:58:58 GMT
Etag: “575e1f71-115”
Last-Modified: Mon, 13 Jun 2016 02:50:25 GMT
Pragma: no-cache
Server: bfe/1.0.8.18

[root@node1 ~]

# curl -vv https://www.baidu.com

  • About to connect() to proxy 10.11.0.148 port 808 (#0)
  • Trying 10.11.0.148…
  • Connected to 10.11.0.148 (10.11.0.148) port 808 (#0)
  • Establish HTTP proxy tunnel to www.baidu.com:443

CONNECT www.baidu.com:443 HTTP/1.1
Host: www.baidu.com:443
User-Agent: curl/7.29.0
Proxy-Connection: Keep-Alive

< HTTP/1.1 200 Connection established
< Proxy-agent: CCProxy
<

  • 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=baidu.com,OU=service operation department.,O=”BeiJing Baidu Netcom Science Technology Co., Ltd”,L=beijing,ST=beijing,C=CN
  • start date: Jun 29 00:00:00 2017 GMT
  • expire date: Aug 17 23:59:59 2018 GMT
  • common name: baidu.com
  • issuer: CN=Symantec Class 3 Secure Server CA – G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US
    GET / HTTP/1.1
    User-Agent: curl/7.29.0
    Host: www.baidu.com
    Accept: /

新闻hao123地图视频贴吧更多产品

关于百度 About Baidu

©2017 Baidu 使用百度前必读  意见反馈 京ICP证030173号 

  • Connection #0 to host 10.11.0.148 left intact

作者:郑子明
来源:CSDN
原文:https://blog.csdn.net/reblue520/article/details/80891643
版权声明:本文为博主原创文章,转载请附上博文链接!

Leave a Reply