欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

内网centos服务器yum和docker使用代理服务器上网拉取资源

程序员文章站 2022-06-02 21:41:19
...

1、配置yum使用代理服务器,配置操作系统全局代理,添加如下配置

   vi  /etc/profile

export http_proxy=“http://192.168.20.11:9999”

   source  /etc/profile

指定用户使用可以添加到对应用户家目录的 .bash_profile

2、使用yum list测试是否正常,或者yum安装软件

[[email protected] ~]# yum list |more
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-
: manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile

  • base: mirror.bit.edu.cn
  • extras: ftp.sjtu.edu.cn
  • updates: ftp.sjtu.edu.cn
    Installed Packages
    NetworkManager.x86_64 1:1.18.4-3.el7 @anaconda
    NetworkManager-libnm.x86_64 1:1.18.4-3.el7 @anaconda
    NetworkManager-team.x86_64 1:1.18.4-3.el7 @anaconda
    NetworkManager-tui.x86_64 1:1.18.4-3.el7 @anaconda
    PyYAML.x86_64 3.10-11.el7 @base
    abrt.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-addon-ccpp.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-addon-kerneloops.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-addon-pstoreoops.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-addon-python.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-addon-vmcore.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-addon-xorg.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-cli.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-dbus.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-libs.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-python.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-retrace-client.x86_64 2.1.11-57.el7.centos @anaconda
    abrt-tui.x86_64 2.1.11-57.el7.centos @anaconda
    acl.x86_64 2.2.51-15.el7 @anaconda
    aic94xx-firmware.noarch 30-6.el7 @anaconda
    alsa-firmware.noarch 1.0.28-2.el7 @anaconda
    alsa-lib.x86_64 1.1.8-1.el7 @anaconda
    alsa-tools-firmware.x86_64 1.1.0-1.el7 @anaconda
    apr.x86_64 1.4.8-5.el7 @anaconda
    apr-util.x86_64 1.5.2-6.el7 @anaconda
    atomic-registries.x86_64 1:1.22.1-33.gitb507039.el7_8
    @extras
    audit.x86_64 2.8.5-4.el7 @anaconda
    audit-libs.x86_64 2.8.5-4.el7 @anaconda
    audit-libs-python.x86_64 2.8.5-4.el7 @base
    augeas-libs.x86_64 1.4.0-9.el7 @anaconda
    authconfig.x86_64 6.2.8-30.el7 @anaconda
    autoconf.noarch 2.69-11.el7 @anaconda
    automake.noarch 1.13.4-3.el7 @anaconda
    avahi-libs.x86_64 0.6.31-20.el7 @anaconda
    …………

3、docker配置http代理服务器

没有如下路径创建即可

 vi /etc/systemd/system/docker.service.d/http-proxy.conf

[Service] Environment=“HTTP_PROXY=http://192.168.20.11:9999” “NO_PROXY=localhost,127.0.0.1”

重新加载systemctl和重启docker

systemctl daemon-reload
systemctl restart docker

我本地http代理访问https需要证书,所以在docker pull时会报如下错误

docker: error response from daemon: get
https://registry-1.docker.io/v2/: x509: certificate signed by unknown
authority.

在如下路径/etc/docker/certs.d/创建registry-1.docker.io 文件夹,名称是上面报错误的网址,将ca证书放置到此路径下

[[email protected] registry-1.docker.io]# pwd
/etc/docker/certs.d/registry-1.docker.io
[[email protected] registry-1.docker.io]# ls
ca.crt

重启docker服务

systemctl  restart  docker

输入命令测试

docker pull centos

[[email protected] registry-1.docker.io]# docker pull hello-world
Using default tag: latest
Trying to pull repository docker.io/library/hello-world …
latest: Pulling from docker.io/library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:4cf9c47f86df71d48364001ede3a4fcd85ae80ce02ebad74156906caff5378bc
Status: Downloaded newer image for docker.io/hello-world:latest