├── .github └── workflows │ └── workflow.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md └── files ├── config.yaml └── start.sh /.github/workflows/workflow.yml: -------------------------------------------------------------------------------- 1 | name: Check update everyday 2 | 3 | on: 4 | schedule: 5 | - cron: "0 1 * * *" 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: Check update 13 | env: 14 | token: ${{ secrets.DOCKERHUB_TOKEN }} 15 | run: | 16 | publish_date1=$(curl -sX GET "https://api.github.com/repos/Dreamacro/clash/releases/latest" | awk '/published_at/{print $4;exit}' FS='[""]') 17 | publish_date2=$(curl -sX GET "https://api.github.com/repos/Dreamacro/clash-dashboard/releases/latest" | awk '/published_at/{print $4;exit}' FS='[""]') 18 | build_date=$(curl -sX GET "https://hub.docker.com/v2/repositories/zyao89/clash-with-dashboard/" | grep -oP '(?<="last_updated": ")[^"]*' | cut -d '.' -f1 | awk '{print $1"Z"}') 19 | if [ $publish_date1 \> $build_date ] || [ $publish_date2 \> $build_date ] 20 | then 21 | curl -X POST https://hub.docker.com/api/build/v1/source/499faf65-e6d4-4b23-a3f7-7d62096e8ca6/trigger/$token/call/ 22 | else 23 | echo up to date 24 | fi 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | temp 2 | build.sh 3 | test 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:latest as builder 2 | 3 | WORKDIR /app 4 | RUN git clone https://github.com/Dreamacro/clash-dashboard.git . 5 | RUN yarn && yarn run build 6 | 7 | # step 2 8 | 9 | FROM dreamacro/clash:latest 10 | 11 | LABEL maintainer "zyao89 " 12 | 13 | RUN mkdir -p /preset-conf \ 14 | && mkdir -p /root/.config/clash \ 15 | && apk add --no-cache darkhttpd iptables net-tools curl vim 16 | 17 | COPY --from=builder /app/dist /ui 18 | 19 | RUN cd \ 20 | && wget https://github.com/haishanh/yacd/archive/gh-pages.zip \ 21 | # 解压缩并且把目录名改成 dashboard 22 | && unzip gh-pages.zip \ 23 | && rm -rf gh-pages.zip \ 24 | && mv yacd-gh-pages/ /dashboard 25 | 26 | COPY files/config.yaml /preset-conf/config.yaml 27 | 28 | COPY files/start.sh /start.sh 29 | RUN chmod +x /start.sh 30 | 31 | VOLUME ["/root/.config/clash"] 32 | 33 | WORKDIR / 34 | EXPOSE 7890 35 | EXPOSE 7891 36 | EXPOSE 9090 37 | EXPOSE 80 38 | 39 | ENTRYPOINT [] 40 | 41 | CMD ["/start.sh"] 42 | HEALTHCHECK --interval=5s --timeout=1s CMD ps | grep darkhttpd | grep -v grep || exit 1 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 zyao89 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Clash, with Dashboard 2 | 3 | [![Docker Build Status](https://img.shields.io/docker/build/zyao89/clash-with-dashboard.svg)](https://hub.docker.com/r/zyao89/clash-with-dashboard) [![Docker Automated build](https://img.shields.io/docker/automated/zyao89/clash-with-dashboard.svg)](https://hub.docker.com/r/zyao89/clash-with-dashboard) [![Docker Stars](https://img.shields.io/docker/stars/zyao89/clash-with-dashboard.svg)](https://hub.docker.com/r/zyao89/clash-with-dashboard) [![Docker Pulls](https://img.shields.io/docker/pulls/zyao89/clash-with-dashboard.svg)](https://hub.docker.com/r/zyao89/clash-with-dashboard) 4 | 5 | This Dockerfile build an image for [clash](https://github.com/dreamacro/clash) with [clash-dashboard](https://github.com/dreamacro/clash-dashboard) frontends. 6 | 7 | ## Quick Start 8 | 9 | ```shell 10 | docker run -d --name clash-dashboard \ 11 | -p 80:80 -p 7890:7890 -p 7891:7891 \ 12 | -v ./config.yaml:/root/.config/clash/config.yaml \ 13 | zyao89/clash-with-dashboard 14 | ``` 15 | 16 | ## Docker Compose 17 | 18 | ```yaml 19 | version: "3" 20 | 21 | services: 22 | clash: 23 | container_name: clash 24 | image: zyao89/clash-with-dashboard 25 | restart: always 26 | ports: 27 | - "7890:7890" 28 | - "7891:7891" 29 | - "80:80" 30 | volumes: 31 | - ./config.yaml:/root/.config/clash/config.yaml 32 | ``` 33 | 34 | ## Thanks 35 | 36 | This docker image is based on [dreamacro](https://hub.docker.com/r/dreamacro/clash/)'s docker image. 37 | -------------------------------------------------------------------------------- /files/config.yaml: -------------------------------------------------------------------------------- 1 | port: 7890 2 | socks-port: 7891 3 | 4 | # redir port for Linux and macOS 5 | redir-port: 7892 6 | 7 | # `allow-lan` must be true in your config.yaml 8 | allow-lan: true 9 | external-controller: 0.0.0.0:9090 10 | 11 | # dashboard folder 12 | # external-ui: /ui 13 | -------------------------------------------------------------------------------- /files/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | PUID=${PUID:=0} 5 | PGID=${PGID:=0} 6 | 7 | # proxy 8 | TRANSPARENT_PROXY=${TRANSPARENT_PROXY:=false} 9 | REDIR_PORT=${REDIR_PORT:=7892} 10 | 11 | THEME=${THEME:='ui'} 12 | 13 | if [ ! -f /root/.config/clash/config.yaml ]; then 14 | cp /preset-conf/config.yaml /root/.config/clash/config.yaml 15 | chown $PUID:$PGID /root/.config/clash/config.yaml 16 | fi 17 | 18 | if [ $TRANSPARENT_PROXY = 'true' ]; then 19 | echo "open TRANSPARENT_PROXY" 20 | 21 | reset_iptables(){ 22 | iptables -P INPUT ACCEPT 23 | iptables -P FORWARD ACCEPT 24 | iptables -P OUTPUT ACCEPT 25 | iptables -t nat -F 26 | iptables -t mangle -F 27 | iptables -F 28 | iptables -X 29 | } 30 | 31 | set_clash_iptables(){ 32 | # 在 nat 表中创建新链 33 | iptables -t nat -N CLASHRULE 34 | 35 | # iptables -t nat -A CLASHRULE -p tcp --dport 1905 -j RETURN 36 | 37 | iptables -t nat -A CLASHRULE -d 0.0.0.0/8 -j RETURN 38 | iptables -t nat -A CLASHRULE -d 10.0.0.0/8 -j RETURN 39 | iptables -t nat -A CLASHRULE -d 127.0.0.0/8 -j RETURN 40 | iptables -t nat -A CLASHRULE -d 169.254.0.0/16 -j RETURN 41 | iptables -t nat -A CLASHRULE -d 172.16.0.0/12 -j RETURN 42 | iptables -t nat -A CLASHRULE -d 192.168.0.0/16 -j RETURN 43 | iptables -t nat -A CLASHRULE -d 224.0.0.0/4 -j RETURN 44 | iptables -t nat -A CLASHRULE -d 240.0.0.0/4 -j RETURN 45 | iptables -t nat -A CLASHRULE -p tcp -j REDIRECT --to-ports $REDIR_PORT 46 | 47 | #拦截 dns 请求并且转发! 48 | # iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53 49 | # iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53 50 | 51 | # 在 PREROUTING 链前插入 CLASHRULE 链,使其生效 52 | iptables -t nat -A PREROUTING -p tcp -j CLASHRULE 53 | } 54 | 55 | reset_iptables 56 | set_clash_iptables 57 | 58 | #开启转发 59 | touch /etc/sysctl.d/proxy.conf 60 | echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.d/proxy.conf && sysctl -p 61 | echo "net.ipv6.conf.all.forwarding = 1" >> /etc/sysctl.d/proxy.conf && sysctl -p 62 | 63 | iptables-save > /etc/iptables/rules.v4 64 | 65 | if [ -f /root/.config/clash/config.yaml ]; then 66 | if [ -z "`grep "redir-port" /root/.config/clash/config.yaml`" ]; then 67 | sed -i '$a redir-port: '${REDIR_PORT} /root/.config/clash/config.yaml 68 | else 69 | sed -i "s@redir-port.*@redir-port: $REDIR_PORT@g" /root/.config/clash/config.yaml 70 | fi 71 | fi 72 | fi 73 | 74 | chown $PUID:$PGID /root/.config/clash || echo 'Failed to set owner of /root/.config/clash' 75 | 76 | darkhttpd /$THEME --port 80 & 77 | 78 | exec /clash 79 | --------------------------------------------------------------------------------