跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] Centos7 Docker 使用 shadowsocks-libev 代理拉取镜像指南

发表于

由于一些众所周知的原因,国内无法继续正常拉取 docker 镜像源了,但是对于本人和大部分 V 友肯定有代理 VPN ,我先说说我的情况,我有两台 VPN ,一台香港的,一台硅谷的。分别都安装了 shadowsocks-libev ,作为服务端去给我日常的设备提供 VPN 。我家里内网的服务器是 Centos7 系统,它没有安装 VPN 客户端,下面是我给它安装客户端并且设置 docker 代理走 socks5 的过程,最终可以正常拉取官方镜像库的镜像。下面是我自己网站的原文内容:

👉 https://www.huhailong.vip/article/1807056397267898370

不想在我网站查看到话直接浏览下面的内容,我复制过来了:

本文介绍的是我自己的解决方案,因为我有两台云服务器,一台香港的,一台硅谷的,所以还是可以正常访问到外网的,只不过需要对现有的内网服务器进行配置,自己使用的电脑就不说了,有 VPN 直接使用,下面主要介绍在服务器环境下如何配置,我家里的服务器是 Centos7 ,所以就以它为例。

安装 shadowsocks-libev

如果你的服务器是 Ubuntu 系统的话直接可以通过命令安装,下面我把它的官方 GitHub 放到下面。 shadowsocks-libev github 在 Centos 中我们需要先添加一下 yum 源,然后再通过 yum 命令去安装,依次执行下面的三条命令。

cd /etc/yum.repos.d/
yum.repos.d]# curl -O https://copr.fedorainfracloud.org/coprs/librehat/shadowsocks/repo/epel-7/librehat-shadowsocks-epel-7.repo
yum install -y shadowsocks-libev

验证安装

完成安装后会有这些命令可以使用:ss-local, ss-manager, ss-nat, ss-redir, ss-server, ss-tunnel 。因为我们此时是想作为客户端使用,所以只需要关注 ss-local 命令。我们直接执行ss-local命令,我的直接运行成功。如果抱错:ss-local: error while loading shared libraries: libmbedcrypto.so.0: cannot open shared object file: No such file or directory ,则使用 root 身份执行下面的命令:

cd /usr/lib64
ln -s libmbedcrypto.so.1 libmbedcrypto.so.0

添加配置文件

安装完后它默认会在/etc/shadowsocks-libev/下面创建了一个名为config.json的文件。如下:

{
	"server": "example.zzz.buzz",
	"server_port": 10443,
	"local_port": 1080,
	"password": "zzz.buzz",
	"method": "aes-256-cfb",
	"mode": "tcp_and_udp",
	"timeout": 600
}
  • server: 必填项,对应填入服务端的 IP 就可以
  • server_port: 必填项,对应服务端暴露出允许连接的端口号
  • local_port: 必填项,本地 shadowsocks 客户端 SOCKS5 代理要监听的端口
  • password: 必填项,对应服务端对应该端口设置的密码
  • method: 必填项,对应服务端的加密方式
  • mode: 选填,默认 tcp_only
  • timeout: 选填,不活动时保持的时间,默认 60 秒

启动客户端

启动客户端执行下面的命令

systemctl enable --now shadowsocks-libev-local
systemctl start shadowsocks-libev-local

执行完上面的命令后同时也设置了开机自启,至此完成了所有的配置,下面看看状态是否成功。

systemctl status shadowsocks-libev-local

如果要查看所有日志可以通过下面的命令

journalctl -u shadowsocks-libev-local

配置 Docker Socks5 代理

启动后如果我们直接拉取发现还是不行,这是因为 docker 没有配置代理的问题,我们本地的 1080 是 socks5 协议,因此我们接下来为 Docker 配置一下代理,这样 docker 的所有网络请求就会通过我们的代理。

创建配置文件

首先创建文件夹 /etc/systemd/system/docker.service.d ,如果有的话就不用了,然后在文件夹下创建一个 http-proxy.conf 文件,名称无所谓,主要以.conf 为后缀就行。然后在里面配置如下内容:

[Service]
Environment="HTTP_PROXY=socks5://127.0.0.1:1080"
Environment="HTTPS_PROXY=socks5://127.0.0.1:1080"

重启生效

systemctl daemon-reload
systemctl restart docker

验证效果

docker pull openjdk:17-jdk-alpine

下面是拉取截图 image.png

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.