Docker 安装clash 代理工具

内容目录

一、前期准备

在宿主机上创建目录 <code>~/config/clash</code> 创建文件 <code>config.yaml</code> 基础内容如下:

port: 7890
socks-port: 7891
allow-lan: true
mode: rule
log-level: info
external-controller: 0.0.0.0:9090 
secret: "你的secret"
  • 7890 为 <code>http://</code> 和 <code>https://</code> 的代理接口
  • 7891 为 socks 的代理接口
  • 9090 为数据配置接口 配合UI面板使用

代理IP由已获得 clash 格式内容中的 <code>external-controller</code> 一下部分 复制到配置文件下方

二、安装

使用 docker-compose 部署

version: '3.7'
networks:
  clash: # 网络名称
    driver: bridge # 驱动方式:桥接

services:
  clash:
    image: metacubex/mihomo
    container_name: clash
    restart: always
    # network_mode: clash #设置现有的网络
    networks: #设置当前配置中的网络
      - clash
    ports:
      - "5090:9090"
      - "7890:7890"
      - "7891:7891"
    volumes:
      - /share/soul/clash/config:/root/.config/mihomo # 改成自己的目录
  clash-ui:
    image: haishanh/yacd:master
    container_name: clash-ui
    restart: always
    # network_mode: clash #设置现有的网络
    networks: #设置当前配置中的网络
      - clash
    ports:
      - 9090:80

三、代理

ip 需更换为网关地址
NO_PROXY 为不走代理地址

1、容器启动时增加环境变量

services: 
    myapp: 
        image: 你的镜像 
        environment: 
        - HTTP_PROXY=http://172.17.0.1:7890 
        - HTTPS_PROXY=http://172.17.0.1:7890 
        - NO_PROXY=localhost,127.0.0.1,172.17.0.1

2、Docker Run 形式

docker run -d \ 
--name myapp \ 
--restart always \ 
-e HTTP_PROXY=http://172.17.0.1:7890 \ 
-e HTTPS_PROXY=http://172.17.0.1:7890 \ 
-e NO_PROXY=localhost,127.0.0.1,.docker.internal \ 你的镜像名

3、容器内设置环境变量

临时使用

export HTTP_PROXY=http://172.29.16.1:7890
export HTTPS_PROXY=http://172.29.16.1:7890
export NO_PROXY=localhost,127.0.0.1,172.29.16.1
3.1、当前用户永久(推荐)

运行

nano ~/.bashrc

在文件最后添加:

export HTTP_PROXY=http://172.17.0.1:7890
export HTTPS_PROXY=http://172.17.0.1:7890
export NO_PROXY=localhost,127.0.0.1,192.168.0.0/16

生效:

source ~/.bashrc
3.2、系统全局永久

运行

nano /etc/profile

添加同样内容,然后:

运行

source /etc/profile
3.3、查看是否修改成功

运行

env | grep -i proxy

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注