Intro

正好在偷师代码,无聊水一篇,为了给自己本年度计划增强执行力 😊

加之最近有不少“战友”都纷纷选择弃坑改“华润万家”去了🇸🇬,有感而发 😪

Docker

修改默认配置 /etc/docker/daemon.json ,增加 registry-mirrors,如下:

{
  "registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com"
  ]
}

顺手重启服务

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

其他OS参考 https://yeasy.gitbook.io/docker_practice/install/mirror

PIP

通常我们都会修改当前用户的 .pip/pip.conf

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn

在容器中显然通过修改 Dockerfile 避免 sed\awk 等命令的私用较为方便,如下:

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U # Upgrade if necessary
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

Go

首先是下载镜像,类似 Ubuntu 的发行版最新的Go已经改用Snap安装了,在 Dockerfile 中和配置Java环境一样,习惯通过下载再手动设定环境变量来实现。

下载地址替换 https://golang.google.cn/g/dl/go/$version

较新的Go版本(>=1.13)支持使用 Goproxy,直接通过命令替换 go env -w GOPROXY="https://goproxy.cn,direct"

GIT

在镜像中当然是直接CLI方式配置更方便,但是进来发现此服务存在DNS劫持

git config --global url."https://hub.fastgit.xyz/".insteadOf "https://github.com/"
git config protocol.https.allow always # ref - https://github.com/git/git/blob/master/Documentation/config/protocol.txt

下载的话修改地址为 download.fastgit.org

参考 https://github.com/dotnetcore/FastGithub

APT

通常来说也是修改 /etc/apt/source* 的相关配置,两种方案,一种是通过 apt 配置代理,显示不是最优解,一种仍然是使用 sed\awk 来修改源,以 Ubuntu 发行版为例:

sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
# in China
sed -i 's/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

参考 https://mirrors.ustc.edu.cn/help/ubuntu.html

Combined together

这里以 https://github.com/yogeshojha/rengine/blob/master/web/Dockerfile 为例,Patch Diff 如下:

diff --git a/web/Dockerfile b/web/Dockerfile
index 4e31dd9d..345b1561 100644
--- a/web/Dockerfile
+++ b/web/Dockerfile
@@ -15,6 +15,8 @@ ENV PYTHONDONTWRITEBYTECODE 1
 ENV PYTHONUNBUFFERED 1

 # Install essentials
+RUN sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && apt clean
+
 RUN apt update -y && apt install -y  --no-install-recommends \
     build-essential \
     cmake \
@@ -40,13 +42,14 @@ RUN apt update -y && apt install -y  --no-install-recommends \


 # Download and install go 1.17
-RUN wget https://golang.org/dl/go1.17.2.linux-amd64.tar.gz
+RUN wget https://golang.google.cn/dl/go1.17.2.linux-amd64.tar.gz
 RUN tar -xvf go1.17.2.linux-amd64.tar.gz
 RUN rm go1.17.2.linux-amd64.tar.gz
 RUN mv go /usr/local

 # Download geckodriver
-RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
+RUN git config --global url."https://hub.fastgit.xyz/".insteadOf "https://github.com/"
+RUN wget https://download.fastgit.org/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
 RUN tar -xvf geckodriver-v0.26.0-linux64.tar.gz
 RUN rm geckodriver-v0.26.0-linux64.tar.gz
 RUN mv geckodriver /usr/bin
@@ -67,6 +70,8 @@ ENV PYTHONDONTWRITEBYTECODE 1
 ENV PYTHONUNBUFFERED 1

 # Download Go packages
+RUN go env -w GOPROXY="https://goproxy.cn,direct"
+
 RUN go install -v github.com/hakluke/hakrawler@latest

 RUN GO111MODULE=on go install -v -v github.com/bp0lr/gauplus@latest
@@ -94,6 +99,8 @@ RUN nuclei -update-templates

 # Copy requirements
 COPY ./requirements.txt /tmp/requirements.txt
+RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
+RUN pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
 RUN pip3 install --upgrade setuptools pip && \
     pip3 install -r /tmp/requirements.txt