Skip to content
On this page

fulltclash Dockerfile Analysis

FullTclash 是一个基于 clash 核心的 Telegram 机器人,用于进行全量订阅测试。以下是基本介绍:

FullTclash bot 是一个承载测试任务的 Telegram 机器人(以下简称 bot),目前支持使用 clash 配置文件进行批量联通性测试。支持以下测试项目:

  • Netflix
  • Youtube
  • DisneyPlus
  • Bilibili
  • Steam 货币
  • OpenAI(ChatGPT)
  • 落地 IP 风险(IP 欺诈度)
  • 维基百科

Here is a detailed tutorial on how to deploy FullTClash using Docker, based on the Dockerfile you provided:

Step 1: Preparing the Prerequisites

Before you start, make sure you've prepared the following:

  • Telegram API credentials: You will need your Telegram api_id and api_hash. If you're not sure how to obtain these, please Google it. Note that some Telegram accounts may be blacklisted and not able to use the bot service normally.

  • Telegram Bot Token: Create a bot on Telegram to obtain the bot token. The token should look something like this: `bot_token = "123456:ABC-DEF1234ghIkl-zyx57

Step 2: Clone the FullTClash Repository

Clone the FullTClash repository from GitHub to your local machine. You can use the following command:

bash
git clone https://github.com/AirportR/FullTCore.git

Step 3: Prepare the Dockerfile

Create a Dockerfile in the root directory of the cloned repository with the contents you provided earlier. You can do this using a text editor. Save the file as Dockerfile.

Step 4: Build the Docker Image

Navigate to the directory containing the Dockerfile and build the Docker image using the following command:

bash
docker build -t fulltclash .

This will create a new docker image with tag fulltclash.

Step 5: Set Environment Variables

Set environment variables for your Telegram API credentials and bot token. You can do this by creating a .env file in your project root directory with contents like below:

env
API_ID=<your_telegram_api_id>
API_HASH=<your_telegram_api_hash>
BOT_TOKEN=<your_bot_token>
FONT_FILE_PATH=/app/fonts/NotoSansCJKsc-Regular.otf # Optional if you want to use custom font files.

Make sure to replace <...> placeholders above with actual values.

Note that we are also setting an optional variable called FONT_FILE_PATH. If you have prepared custom fonts, set its path here; otherwise it is not necessary as default fonts will be used instead.

Step 6: Run FullTClash Bot Container

Run FullTClash container from built images via running:

bash
docker run --name=FullTCBot \
-e "TZ=Asia/Shanghai" \   # Change timezone according yours needs.
--restart unless-stopped \
-d fulltclash
  1. Base Image Selection:

    dockerfile
    FROM golang:1.20.7-alpine AS builder

    This line specifies that the base image for building the application will be Alpine Linux with Golang version 1.20.7.

  2. Builder Stage:

    dockerfile
    WORKDIR /app/fulltclash-meta
    RUN apk add --no-cache upx git
    RUN git clone -b meta https://github.com/AirportR/FullTCore.git /app/fulltclash-meta && \
        go build -tags with_gvisor -ldflags="-s -w" fulltclash.go && \
        mkdir /app/FullTCore-file && \
        cp /app/fulltclash-meta/fulltclash /app/FullTCore-file/fulltclash-meta && \
        chmod +x /app/FullTCore-file/fulltclash-meta && \
        upx -9 /app/FullTCore-file/fulltclash-meta

    In this section, several actions are performed in the builder stage:

    • The working directory is set to /app/fulltclash-meta.
    • Alpine Linux package manager (apk) is used to install upx and git.
    • The repository https://github.com/AirportR/FullTCore.git is cloned, and the fulltclash.go file is built using the Go compiler with specific flags. The resulting binary is then optimized using upx and placed in the /app/FullTCore-file directory.
  3. Downloading and Setting Up 'gost':

    dockerfile
    RUN wget -t 2 -T 10 https://github.com/go-gost/gost/releases/download/v3.0.0-rc8/gost_3.0.0-rc8_linux_amd64v3.tar.gz && \
        tar -xzvf gost_3.0.0-rc8_linux_amd64v3.tar.gz && \
        chmod +x gost && \
        upx -9 gost && \
        mv gost /bin/gost && \
        rm -f gost_3.0.0-rc8_linux_amd64v3.tar.gz

    This section downloads the gost binary, extracts it, makes it executable, optimizes it with upx, and then moves it to the /bin directory.

  4. Second Stage (Final Image):

    dockerfile
    FROM python:alpine3.18

    This sets the final image to be based on Alpine Linux with Python version 3.18.

  5. Setting Up Environment Variables and Copying Files:

    dockerfile
    WORKDIR /app
    ENV TZ=Asia/Shanghai
    ENV CORE=1
    ENV THREAD=4
    ENV PROXY=0
    COPY . /app

    The working directory is set to /app, and some environment variables are defined. The contents of the current directory (presumably the application source files) are copied into the image.

  6. Installing Dependencies and Configuring Timezone:

    dockerfile
    RUN apk add --no-cache \
        git gcc g++ make libffi-dev tzdata && \
        pip3 install --no-cache-dir -r requirements.txt && \
        cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
        echo "Asia/Shanghai" > /etc/timezone && \
        apk del gcc g++ make libffi-dev tzdata && \
        rm -f bin/* *.md LICENSE /var/cache/apk/*

    Here, the Alpine Linux package manager is used to install various dependencies, including compilers and libraries. Python packages are installed using pip3. The timezone is set to "Asia/Shanghai." After installation, unnecessary files are removed to reduce image size.

  7. Copying Files from Builder Stage and Setting Permissions:

    dockerfile
    COPY --from=builder /app/FullTCore-file/* ./bin/
    COPY --from=builder /bin/gost /bin/gost
    RUN  chmod -R +x .

    The optimized fulltclash-meta binary and the gost binary from the builder stage are copied into the bin/ directory of the final image. Additionally, execute permissions are recursively added to all files in the image.

  8. Setting the Entry Point:

    dockerfile
    ENTRYPOINT ["sh", "main.sh"]

    The entry point for the image is set to execute the main.sh shell script when the container is run.

Overall, this Dockerfile defines a multi-stage build process to create an image that includes a Golang application and a Python application, along with some dependencies and configuration settings. The resulting image is intended to run the specified applications within a Docker container.

fulltclash Dockerfile full version

dockerfile
FROM golang:1.20.7-alpine AS builder

# WORKDIR /app/fulltclash-origin
# RUN apk add --no-cache git && \
#     git clone https://github.com/AirportR/FullTCore.git /app/fulltclash-origin && \
#     go build -ldflags="-s -w" fulltclash.go

WORKDIR /app/fulltclash-meta
RUN apk add --no-cache upx git
RUN git clone -b meta https://github.com/AirportR/FullTCore.git /app/fulltclash-meta && \
    go build -tags with_gvisor -ldflags="-s -w" fulltclash.go && \
    mkdir /app/FullTCore-file && \
    cp /app/fulltclash-meta/fulltclash /app/FullTCore-file/fulltclash-meta && \
    chmod +x /app/FullTCore-file/fulltclash-meta && \
    upx -9 /app/FullTCore-file/fulltclash-meta
# Download, extract, chmod and clean gost
RUN wget -t 2 -T 10 https://github.com/go-gost/gost/releases/download/v3.0.0-rc8/gost_3.0.0-rc8_linux_amd64v3.tar.gz && \
    tar -xzvf gost_3.0.0-rc8_linux_amd64v3.tar.gz && \
    chmod +x gost && \
    upx -9 gost && \
    mv gost /bin/gost && \
    rm -f gost_3.0.0-rc8_linux_amd64v3.tar.gz

FROM python:alpine3.18

WORKDIR /app

ENV TZ=Asia/Shanghai
ENV CORE=1
ENV THREAD=4
ENV PROXY=0

COPY . /app

RUN apk add --no-cache \
    git gcc g++ make libffi-dev tzdata && \
    pip3 install --no-cache-dir -r requirements.txt && \
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone && \
    apk del gcc g++ make libffi-dev tzdata && \
    rm -f bin/* *.md LICENSE /var/cache/apk/*

COPY --from=builder /app/FullTCore-file/* ./bin/
# gost binary
COPY --from=builder /bin/gost /bin/gost

RUN  chmod -R +x .
# CMD ["main.py"]
# ENTRYPOINT ["python3"]
ENTRYPOINT ["sh", "main.sh"]

main.sh content

bash
#!/bin/sh
# start pm2 run main.py and gost in no daemon mode
gost -L mws://pass@:7860?path=/ws &
python3 main.py

上次更新于: