├── .dockerignore ├── .gitignore ├── Dockerfile ├── Procfile ├── README.md ├── build.sh ├── caddy ├── .config.json ├── html │ └── .index.html └── logs │ └── .gitignore ├── main.sh ├── screenshot.jpg └── v2ray ├── .config.json └── logs └── .gitignore /.dockerignore: -------------------------------------------------------------------------------- 1 | README.md 2 | screenshot.jpg 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM caddy:2.2.1-alpine 2 | LABEL maintainer "nekocode " 3 | 4 | # Install necessary libs 5 | RUN apk add --no-cache bash logrotate curl tar util-linux 6 | 7 | # Install forego 8 | ARG FOREGO_VERSION="ekMN3bCZFUn" 9 | RUN curl "https://bin.equinox.io/c/${FOREGO_VERSION}/forego-stable-linux-amd64.tgz" -Lo /tmp/forego.tgz 10 | RUN cd /usr/local/bin && tar -xzf /tmp/forego.tgz \ 11 | && chmod +x /usr/local/bin/forego \ 12 | && rm /tmp/forego.tgz 13 | 14 | # 15 | # Install v2ray 16 | # 17 | ARG V2RAY_VERSION="v4.39.2" 18 | ARG TZ="Asia/Shanghai" 19 | ENV TZ ${TZ} 20 | RUN mkdir -p /tmp/v2ray \ 21 | && curl "https://github.com/v2fly/v2ray-core/releases/download/${V2RAY_VERSION}/v2ray-linux-64.zip" -Lo /tmp/v2ray/v2ray.zip \ 22 | && unzip /tmp/v2ray/v2ray.zip -d /tmp/v2ray/ 23 | RUN mv /tmp/v2ray/v2ray /usr/bin \ 24 | && mv /tmp/v2ray/v2ctl /usr/bin \ 25 | && chmod +x /usr/bin/v2ray \ 26 | && chmod +x /usr/bin/v2ctl \ 27 | && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \ 28 | && rm -rf /tmp/v2ray /var/cache/apk/* 29 | 30 | # Copy files 31 | COPY ./main.sh / 32 | COPY ./Procfile / 33 | COPY ./caddy/ /caddy/ 34 | COPY ./v2ray/ /v2ray/ 35 | 36 | EXPOSE 80 443 37 | WORKDIR / 38 | 39 | ENTRYPOINT ["/main.sh"] 40 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | caddy: caddy run --config /caddy/config.json 2 | v2ray: v2ray -config /v2ray/config.json 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 内置应用版本号: 2 | 3 | - caddy: `2.2.1`(释放日期:`2020-10-14`) 4 | - v2ray: `v4.39.2`(释放日期:`2021-05-26`) 5 | 6 | 使用方法: 7 | 8 | ``` 9 | docker pull nekocode/v2ray:latest 10 | 11 | # 将下面的 YOUR_DOMAIN 替换成已经解析到你服务器的域名: 12 | docker run -d -p 80:80 -p 443:443 -e DOMAIN=YOUR_DOMAIN nekocode/v2ray:latest 13 | 14 | # 此外,你还可以为 V2Ray 设置固定的 UUID(否则容器每次启动会自动生成随机 UUID) 15 | docker run -d -p 80:80 -p 443:443 -e DOMAIN=YOUR_DOMAIN -e UUID=YOUR_UUID nekocode/v2ray:latest 16 | ``` 17 | 18 | 容器启动后,在浏览器中访问你的域名将会得到以下网页,它提供了各大平台常用客户端的配置二维码和 vmess 链接: 19 | 20 | 21 | 22 | *Tip: 如果不想该页面太容易暴露出去的话,可以绑定子域名来提高隐匿性,例如 `secret0.yourdomain.com`* 23 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -v 2 | 3 | docker build -t nekocode/v2ray:latest . 4 | 5 | # Test 6 | # docker rm -f test-v2ray 7 | # docker run -d -p 80:80 -p 443:443 -e DOMAIN=localhost --name test-v2ray nekocode/v2ray:latest 8 | -------------------------------------------------------------------------------- /caddy/.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps": { 3 | "http": { 4 | "servers": { 5 | "gateway": { 6 | "listen": [":443"], 7 | "routes": [ 8 | { 9 | "match": [ 10 | { 11 | "host": ["DOMAIN"] 12 | } 13 | ], 14 | "handle": [ 15 | { 16 | "handler": "subroute", 17 | "routes": [ 18 | { 19 | "match": [ 20 | { 21 | "path": ["/v2ray"] 22 | } 23 | ], 24 | "handle": [ 25 | { 26 | "handler": "reverse_proxy", 27 | "upstreams": [ 28 | { 29 | "dial": "localhost:2333" 30 | } 31 | ] 32 | } 33 | ], 34 | "terminal": true 35 | }, 36 | { 37 | "handle": [ 38 | { 39 | "handler": "file_server", 40 | "root": "/caddy/html" 41 | } 42 | ], 43 | "terminal": true 44 | } 45 | ] 46 | } 47 | ], 48 | "terminal": true 49 | } 50 | ] 51 | } 52 | } 53 | } 54 | }, 55 | "logging": { 56 | "logs": { 57 | "file": { 58 | "level": "INFO", 59 | "writer": { 60 | "output": "file", 61 | "filename": "/caddy/logs/access.log", 62 | "roll": true, 63 | "roll_size_mb": 50, 64 | "roll_keep": 5 65 | } 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /caddy/html/.index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | RESPECT! 7 | 8 | 9 | 10 | 11 | 22 | 23 | 24 | 25 | 39 | 40 | 41 | 44 | 45 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /caddy/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /main.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eo pipefail 3 | 4 | if [[ -z $DOMAIN ]]; then 5 | echo "DOMAIN 不能为空" 6 | exit 1 7 | fi 8 | 9 | if [[ -z $UUID ]]; then 10 | UUID="$(uuidgen)" 11 | fi 12 | 13 | echo "DOMAIN 为 \"${DOMAIN}\"" 14 | echo "UUID 为 \"${UUID}\"" 15 | 16 | set -x 17 | 18 | # 配置 caddy 19 | cp -f /caddy/.config.json /caddy/config.json 20 | sed -i "s/DOMAIN/${DOMAIN}/" /caddy/config.json 21 | 22 | # 修改 html 23 | cp -f /caddy/html/.index.html /caddy/html/index.html 24 | sed -i "s/DOMAIN/${DOMAIN}/" /caddy/html/index.html 25 | sed -i "s/UUID/${UUID}/" /caddy/html/index.html 26 | 27 | # 配置 v2ray 28 | cp -f /v2ray/.config.json /v2ray/config.json 29 | sed -i "s/UUID/${UUID}/" /v2ray/config.json 30 | cat /v2ray/config.json 31 | 32 | # 配置 v2ray logrotate 33 | cat >/etc/logrotate.d/v2ray <<'EOF' 34 | /v2ray/logs/*.log { 35 | daily 36 | size 50M 37 | missingok 38 | rotate 5 39 | compress 40 | delaycompress 41 | notifempty 42 | copytruncate 43 | } 44 | EOF 45 | 46 | # 启动 caddy 和 v2ray 47 | forego start 48 | -------------------------------------------------------------------------------- /screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekocode/v2ray-docker/04f1523766c635d2a4392df34568b5d595ce210d/screenshot.jpg -------------------------------------------------------------------------------- /v2ray/.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "log": { 3 | "loglevel": "warning", 4 | "access": "/v2ray/logs/access.log", 5 | "error": "/v2ray/logs/error.log" 6 | }, 7 | "inbounds": [ 8 | { 9 | "port": 2333, 10 | "protocol": "vmess", 11 | "settings": { 12 | "clients": [ 13 | { 14 | "id": "UUID", 15 | "alterId": 0 16 | } 17 | ] 18 | }, 19 | "streamSettings": { 20 | "network": "ws", 21 | "wsSettings": { 22 | "path": "/v2ray" 23 | } 24 | } 25 | } 26 | ], 27 | "outbounds": [ 28 | { 29 | "protocol": "freedom", 30 | "settings": {} 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /v2ray/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore --------------------------------------------------------------------------------