收起左侧

docker compose安装mihomo

9
回复
4258
查看
[ 复制链接 ]

0

主题

0

回帖

0

牛值

江湖小虾

2025-1-7 09:34:27 显示全部楼层 阅读模式

[i=s] 本帖最后由 baiy316 于 2025-1-7 11:06 编辑 [/i]<br /> <br />

一、前言

首先感谢 windowbr 大佬提供的教程。大佬的教程里mihomo的部分是通过页面安装,无法使用 TUN 模式来接管所有设备流量。MetaCubeX/metacubexd 的讨论区有帖子compose安装mihomo的方法,因此汇总整理方便记忆。

二、准备工作

1、拉取mihomo镜像

image.png

2、准备config.yaml文件

创建config.yaml文件,粘贴下方代码;在proxy-providers处替换自己的订阅名称、链接、前缀<记得删括号!>

(再次感谢 windowbr 大佬提供的模板,yaml文件我完全不懂,还好大佬提供的模板非常便捷)

mixed-port: 7890
allow-lan: true
bind-address: '*'
mode: rule
log-level: info
external-controller: '0.0.0.0:9090'

tun:
  enable: true
  stack: mixed
  dns-hijack:
    - "any:53"
    - "tcp://any:53"
  auto-route: true
  auto-redirect: true
  auto-detect-interface: true

proxy-providers:
  <节点提供者名称,记得删括号>:
    url: "<节点订阅链接,记得删括号>"
    type: http
    interval: 86400
    health-check: {enable: true,url: "https://www.gstatic.com/generate_204", interval: 300}
    override:
      additional-prefix: "<节点名称前缀,记得删括号>"

proxies: 
  - name: "直连"
    type: direct
    udp: true

geodata-mode: true
geox-url:
  geoip: "https://**ror.ghproxy.com/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip-lite.dat"
  geosite: "https://**ror.ghproxy.com/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat"
  mmdb: "https://**ror.ghproxy.com/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country-lite.mmdb"
  asn: "https://**ror.ghproxy.com/https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb"

dns:
  enable: true
  ipv6: true
  respect-rules: true
  enhanced-mode: fake-ip
  fake-ip-filter:
    - "*"
    - "+.lan"
    - "+.local"
    - "+.**.xiaomi.com"
  nameserver:
    - https://120.53.53.53/dns-query
    - https://223.5.5.5/dns-query
  proxy-server-nameserver:
    - https://120.53.53.53/dns-query
    - https://223.5.5.5/dns-query
  nameserver-policy:
    "geosite:cn,private":
      - https://120.53.53.53/dns-query
      - https://223.5.5.5/dns-query
    "geosite:geolocation-!cn":
      - "https://dns.cloudflare.com/dns-query"
      - "https://dns.google/dns-query"

proxy-groups:

  - name: 默认
    type: select
    proxies: [自动选择,直连,**,**,日本,新加坡,美国,其它地区,全部节点]

  - name: Google
    type: select
    proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]

  - name: Telegram
    type: select
    proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]

  - name: Twitter
    type: select
    proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]

  - name: 哔哩哔哩
    type: select
    proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]

  - name: 巴哈姆特
    type: select
    proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]

  - name: **
    type: select
    proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]

  - name: NETFLIX
    type: select
    proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]

  - name: Spotify
    type: select
    proxies:  [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]

  - name: Github
    type: select
    proxies:  [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]

  - name: 国内
    type: select
    proxies:  [直连,默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择]

  - name: 其他
    type: select
    proxies:  [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]

  #分隔,下面是地区分组
  - name: **
    type: select
    include-all: true
    filter: "(?i)港|hk|hongkong|hong kong"

  - name: **
    type: select
    include-all: true
    filter: "(?i)台|tw|**"

  - name: 日本
    type: select
    include-all: true
    filter: "(?i)日|jp|japan"

  - name: 美国
    type: select
    include-all: true
    filter: "(?i)美|us|unitedstates|united states"

  - name: 新加坡
    type: select
    include-all: true
    filter: "(?i)(新|sg|singapore)"

  - name: 其它地区
    type: select
    include-all: true
    filter: "(?i)^(?!.*(?:🇭🇰|🇯🇵|🇺🇸|🇸🇬|🇨🇳|港|hk|hongkong|台|tw|**|日|jp|japan|新|sg|singapore|美|us|unitedstates)).*"

  - name: 全部节点
    type: select
    include-all: true

  - name: 自动选择
    type: url-test
    include-all: true
    tolerance: 10

rules:
  - GEOIP,lan,直连,no-resolve
  - GEOSITE,github,Github
  - GEOSITE,twitter,Twitter
  - GEOSITE,**,**
  - GEOSITE,google,Google
  - GEOSITE,telegram,Telegram
  - GEOSITE,netflix,NETFLIX
  - GEOSITE,bilibili,哔哩哔哩
  - GEOSITE,bahamut,巴哈姆特
  - GEOSITE,spotify,Spotify
  - GEOSITE,CN,国内
  - GEOSITE,geolocation-!cn,其他

  - GEOIP,google,Google
  - GEOIP,netflix,NETFLIX
  - GEOIP,telegram,Telegram
  - GEOIP,twitter,Twitter
  - GEOIP,CN,国内
  - MATCH,其他

3、下载文件

该仓库 下载:GeoIP.dat、geoid.metadb、geosite.dat三个文件;

将下载的三个文件以及config.yaml文件放进任意目录中(例:/vol1/1000/docker/mihomo)

至此所有准备工作全部完成。

三、安装

1、打开docker-compose,点击新增项目

image.png

2、项目名称可以随意填写;路径填写保存yml文件的目录;来源选择创建

image.png

3、在文本框内粘贴下方代码

# version: '3'
services:
  mihomo:
    container_name: mihomo
    image: metacubex/mihomo
    restart: always
    pid: host
    ipc: host
    network_mode: host
    cap_add:
      - ALL
    security_opt:
      - apparmor=unconfined
    volumes:
      - /vol1/1000/docker/mihomo:/root/.config/mihomo
      - /dev/net/tun:/dev/net/tun
      # 共享host的时间环境
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro

  metacubexd:
    container_name: metacubexd
    image: ghcr.io/metacubex/metacubexd
    restart: always
    network_mode: bridge
    ports:
      - '9097:80'
    volumes:
      - /vol1/1000/docker/mihomo/metacubexd:/config/caddy
      # 共享host的时间环境
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro

其中:

/vol1/1000/docker/mihomo 需要保持与第二节第3点的目录一致

/vol1/1000/docker/mihomo/metacubexd 是metacube的配置目录

倒数第五行的 9097 是web访问端口,可随意修改

四、使用

浏览器地址栏输入 "IP:9097",可访问metacube(XD)管理界面,后端地址填写 "http://设备IP:9090",密钥为空即可

收藏
送赞 3
分享

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

2

主题

2

回帖

0

牛值

江湖小虾

社区上线纪念勋章

2025-1-21 11:27:39 显示全部楼层
不错不错 收藏一下先

1

主题

3

回帖

0

牛值

江湖小虾

2025-2-18 11:16:26 显示全部楼层
能否把yaml文件发下邮箱95225443@qq.com 改了老是报错 麻烦了

6

主题

4

回帖

0

牛值

江湖小虾

2025-3-8 10:43:36 显示全部楼层
   additional-prefix: "<节点名称前缀,记得删括号>"
这个节点名称前缀该怎么填写?
仅影响节点名称显示 比如前缀为 [机场1],节点本来的名字是 **1 这样节点的名字最后就会显示为 [机场1] **1 比如你在一个配置文件中使用了多个机场的节点时这个改名显示就会让你自己选节点的时候更加方便  详情 回复
2025-3-8 20:59

9

主题

15

回帖

0

牛值

fnOS系统内测组

2025-3-8 20:59:06 显示全部楼层
仅影响节点名称显示
比如前缀为 [机场1],节点本来的名字是 **1
这样节点的名字最后就会显示为 [机场1] **1
比如你在一个配置文件中使用了多个机场的节点时这个改名显示就会让你自己选节点的时候更加方便

0

主题

2

回帖

0

牛值

江湖小虾

2025-3-9 20:38:02 显示全部楼层
https://windowbr.top/2024/11/02/mihomo-docker/参考这个正常了,你的yaml会引起docker反复重启。

0

主题

2

回帖

0

牛值

江湖小虾

2025-3-11 17:17:45 显示全部楼层
飞牛内的docker和容器安装的imm都不能共享科学啊?

2

主题

3

回帖

0

牛值

江湖小虾

2025-3-30 02:18:50 显示全部楼层
因为一个坑折腾了差不多2个小时,最后无奈问deepseek终于知道问题在哪里?
time="2025-03-30T02:13:08.228461753+08:00" level=fatal msg="Parse config error: rules[1] [GEOSITE,github,Github] error: load GeoSite data error, failed to decode geodata file: GeoSite.dat, base error: proto:\u00a0cannot parse invalid wire-format data"

出现这个错误之后,重新从github下载了,但是死活还是不行,最后问了deepseek才知道,文件名需严格匹配 GeoSite.dat 和 GeoIP.dat(区分大小写)。

大小写严格!!!!跟大家说下避一下坑!

3

主题

3

回帖

0

牛值

江湖小虾

2025-4-13 10:34:42 显示全部楼层

只需要改 proxy-providers的内容就行了吗

3

主题

8

回帖

0

牛值

江湖小虾

浏览器地址栏输入 "IP:9097",可访问metacube(XD)管理界面,后端地址填写 "http://设备IP:9090",密钥为空即可。

这里我出问题了,后端地址9090填了进不去,9097才能进去,但是代理空的

[img]https://cdn.jsdelivr.net/gh/master-of-forums/master-of-forums/public/images/patch.gif[/img]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则