国内镜像

使用包管理可以大大降低引用和管理第三方库的成本,但是很多源都在国外,通过包管理安装的时候,容易超时;我们可以通过修改为国内源,或者使用代理来解决这个问题。

Pip

提供方 源及使用方式
豆瓣

https://pypi.doubanio.com/simple/

pip install -i https://pypi.doubanio.com/simple/
清华大学

https://pypi.tuna.tsinghua.edu.cn/simple

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
阿里云

https://mirrors.aliyun.com/pypi/simple/

pip install -i https://mirrors.aliyun.com/pypi/simple/

Composer

提供方 源及使用方式
-

https://packagist.phpcomposer.com/

composer config -g repo.packagist composer https://packagist.phpcomposer.com
-

https://php.cnpkg.org/

composer config -g repo.packagist composer https://php.cnpkg.org
阿里云

https://mirrors.aliyun.com/composer/

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
华为云

https://mirrors.huaweicloud.com/repository/php/

composer config -g repo.packagist composer https://mirrors.huaweicloud.com/repository/php/
上海交通大学

https://packagist.mirrors.sjtug.sjtu.edu.cn/

composer config -g repo.packagist composer https://packagist.mirrors.sjtug.sjtu.edu.cn
-

https://packagist.jp/

composer config -g repo.packagist composer https://packagist.jp

NPM

提供方 源及使用方式
淘宝

https://registry.npmmirror.com/

npm config set registry https://registry.npmmirror.com
pnpm config set registry https://registry.npmmirror.com
yarn config set registry https://registry.npmmirror.com
-

http://r.cnpmjs.org/

npm config set registry http://r.cnpmjs.org/
pnpm config set registry http://r.cnpmjs.org/
yarn config set registry http://r.cnpmjs.org/

Gem

提供方 源及使用方式
Ruby China

https://ruby.taobao.org/

gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
清华大学

https://mirrors.tuna.tsinghua.edu.cn/rubygems/

gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/

Maven

提供方 源及使用方式
阿里云

http://maven.aliyun.com/nexus/content/groups/public/

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"
    xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <mirrors>
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
        <repositories>
          <repository>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <layout>default</layout>
            <url>http://repo1.maven.org/maven2</url>
            <snapshots>
              <enabled>false</enabled>
            </snapshots>
          </repository>
        </repositories>
        <id>offical</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>offical</activeProfile>
  </activeProfiles>
</settings>

代理方式

包管理器 代理方式 使用方式
pip http/https
https_proxy=http://ip:hort pip install
composer http/https
https_proxy=http://ip:hort composer install
npm http/https
npm config set proxy http://ip:port
npm config set https-proxy https://ip:port
yarn config set proxy http://ip:port
yarn config set https-proxy https://ip:port
gem http/https
http_proxy=http://ip:port https_proxy=https://ip:host gem install
go http/https
http_proxy=http://ip:port https_proxy=https://ip:host go get
docker http/https

docker pull,通过 dockerd 执行,需要修改 /etc/systemd/system/docker.service.d/proxy.conf

[Service]
Environment="HTTP_PROXY=http://ip:port/"
Environment="HTTPS_PROXY=http://ip:port/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

之后重启 docker 服务

systemctl daemon-reload
systemctl restart docker
http/https

docker run,影响所有 container,需要修改 ~/.docker/config.json

{
 "proxies": {
   "default": {
     "httpProxy": "http://ip:port",
     "httpsProxy": "http://ip:port",
     "noProxy": "localhost,127.0.0.1,.example.com"
   }
 }
}

docker run,影响当前 container,在命令中指定

docker run --env HTTP_PROXY="http://ip:port" --env HTTPS_PROXY="http://ip:port"
http/https

docker build

docker build . \
    --build-arg "HTTP_PROXY=http://ip:port/" \
    --build-arg "HTTPS_PROXY=http://ip:port/" \
    --build-arg "NO_PROXY=localhost,127.0.0.1,.example.com" \
    -t your/image:tag

引用

  1. Using pip behind a proxy

😉 腾讯云产品特惠热卖,戳我领取

评论

Home - Wiki
Copyright © 2011-2024 iteam. Current version is 2.139.0. UTC+08:00, 2024-12-22 18:02
浙ICP备14020137号-1 $Map of visitor$