From 9e8fadd745c118b78e43ea8b072c24b17ef98258 Mon Sep 17 00:00:00 2001 From: Teddysun Date: Wed, 25 Nov 2020 20:53:52 +0900 Subject: [PATCH] Added Xray Docker Image --- docker/xray/Dockerfile | 26 +++++++++++ docker/xray/Dockerfile.architecture | 27 +++++++++++ docker/xray/README.md | 70 +++++++++++++++++++++++++++++ docker/xray/build_xray.sh | 43 ++++++++++++++++++ docker/xray/config.json | 19 ++++++++ docker/xray/xray.sh | 52 +++++++++++++++++++++ 6 files changed, 237 insertions(+) create mode 100644 docker/xray/Dockerfile create mode 100644 docker/xray/Dockerfile.architecture create mode 100644 docker/xray/README.md create mode 100644 docker/xray/build_xray.sh create mode 100644 docker/xray/config.json create mode 100644 docker/xray/xray.sh diff --git a/docker/xray/Dockerfile b/docker/xray/Dockerfile new file mode 100644 index 0000000..ce8f261 --- /dev/null +++ b/docker/xray/Dockerfile @@ -0,0 +1,26 @@ +# Dockerfile for xray based alpine +# Copyright (C) 2019 - 2020 Teddysun +# Reference URL: +# https://github.com/XTLS/Xray-core +# https://github.com/v2ray/v2ray-core +# https://github.com/v2ray/geoip +# https://github.com/v2ray/domain-list-community + +FROM alpine:latest +LABEL maintainer="Teddysun " + +WORKDIR /root +COPY xray.sh /root/xray.sh +COPY config.json /etc/xray/config.json +RUN set -ex \ + && apk add --no-cache tzdata ca-certificates \ + && mkdir -p /var/log/xray \ + && chmod +x /root/xray.sh \ + && /root/xray.sh \ + && rm -fv /root/xray.sh \ + && wget -O /usr/bin/geosite.dat https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat \ + && wget -O /usr/bin/geoip.dat https://github.com/v2fly/geoip/releases/latest/download/geoip.dat + +VOLUME /etc/xray +ENV TZ=Asia/Shanghai +CMD [ "/usr/bin/xray", "-config", "/etc/xray/config.json" ] diff --git a/docker/xray/Dockerfile.architecture b/docker/xray/Dockerfile.architecture new file mode 100644 index 0000000..8b4a755 --- /dev/null +++ b/docker/xray/Dockerfile.architecture @@ -0,0 +1,27 @@ +# Dockerfile for xray based alpine +# Copyright (C) 2019 - 2020 Teddysun +# Reference URL: +# https://github.com/XTLS/Xray-core +# https://github.com/v2ray/v2ray-core +# https://github.com/v2ray/geoip +# https://github.com/v2ray/domain-list-community + +FROM --platform=${TARGETPLATFORM} alpine:latest +LABEL maintainer="Teddysun " + +ARG TARGETPLATFORM +WORKDIR /root +COPY xray.sh /root/xray.sh +COPY config.json /etc/xray/config.json +RUN set -ex \ + && apk add --no-cache tzdata ca-certificates \ + && mkdir -p /var/log/xray \ + && chmod +x /root/xray.sh \ + && /root/xray.sh "${TARGETPLATFORM}" \ + && rm -fv /root/xray.sh \ + && wget -O /usr/bin/geosite.dat https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat \ + && wget -O /usr/bin/geoip.dat https://github.com/v2fly/geoip/releases/latest/download/geoip.dat + +VOLUME /etc/xray +ENV TZ=Asia/Shanghai +CMD [ "/usr/bin/xray", "-config", "/etc/xray/config.json" ] diff --git a/docker/xray/README.md b/docker/xray/README.md new file mode 100644 index 0000000..9e08a7b --- /dev/null +++ b/docker/xray/README.md @@ -0,0 +1,70 @@ +## Xray Docker Image by Teddysun + +[Xray][1] is a platform for building proxies to bypass network restrictions. + +It secures your network connections and thus protects your privacy. + +Docker images are built for quick deployment in various computing cloud providers. + +For more information on docker and containerization technologies, refer to [official document][2]. + +## Prepare the host + +If you need to install docker by yourself, follow the [official installation guide][3]. + +## Pull the image + +```bash +$ docker pull teddysun/xray +``` + +This pulls the latest release of Xray. + +It can be found at [Docker Hub][4]. + +## Start a container + +You **must create a configuration file** `/etc/xray/config.json` in host at first: + +``` +$ mkdir -p /etc/xray +``` + +A sample in JSON like below: + +``` +{ + "inbounds": [{ + "port": 9000, + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "1eb6e917-774b-4a84-aff6-b058577c60a5", + "level": 1, + "alterId": 64 + } + ] + } + }], + "outbounds": [{ + "protocol": "freedom", + "settings": {} + }] +} +``` + +Or generate a configuration file online by [https://tools.sprov.xyz/v2ray/](https://tools.sprov.xyz/v2ray/) + +There is an example to start a container that listen on port `9000`, run as a Xray server like below: + +```bash +$ docker run -d -p 9000:9000 --name xray --restart=always -v /etc/xray:/etc/xray teddysun/xray +``` + +**Warning**: The port number must be same as configuration and opened in firewall. + +[1]: https://github.com/XTLS/Xray-core +[2]: https://docs.docker.com/ +[3]: https://docs.docker.com/install/ +[4]: https://hub.docker.com/r/teddysun/xray/ \ No newline at end of file diff --git a/docker/xray/build_xray.sh b/docker/xray/build_xray.sh new file mode 100644 index 0000000..abc0294 --- /dev/null +++ b/docker/xray/build_xray.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# +# This is a Shell script for build multi-architectures v2ray binary file +# +# Supported architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x +# +# Copyright (C) 2020 Teddysun +# +# Reference URL: +# https://github.com/XTLS/Xray-core + +cur_dir="$(pwd)" + +COMMANDS=( git go ) +for CMD in "${COMMANDS[@]}"; do + if [ ! "$(command -v "${CMD}")" ]; then + echo "${CMD} is not installed, please install it and try again" && exit 1 + fi +done + +cd ${cur_dir} +git clone https://github.com/XTLS/Xray-core.git +cd Xray-core || exit 2 + +LDFLAGS="-s -w" +ARCHS=( 386 amd64 arm arm64 ppc64le s390x ) +ARMS=( 6 7 ) + +for ARCH in ${ARCHS[@]}; do + if [ "${ARCH}" = "arm" ]; then + for V in ${ARMS[@]}; do + echo "Building xray_linux_${ARCH}${V}" + env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GOARM=${V} go build -v -trimpath -ldflags "${LDFLAGS}" -o ${cur_dir}/xray_linux_${ARCH}${V} ./main || exit 1 + done + else + echo "Building xray_linux_${ARCH}" + env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -trimpath -ldflags "${LDFLAGS}" -o ${cur_dir}/xray_linux_${ARCH} ./main || exit 1 + fi +done + +chmod +x ${cur_dir}/xray_linux_* +# clean up +cd ${cur_dir} && rm -fr Xray-core diff --git a/docker/xray/config.json b/docker/xray/config.json new file mode 100644 index 0000000..9dded72 --- /dev/null +++ b/docker/xray/config.json @@ -0,0 +1,19 @@ +{ + "inbounds": [{ + "port": 9000, + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "1eb6e917-774b-4a84-aff6-b058577c60a5", + "level": 1, + "alterId": 64 + } + ] + } + }], + "outbounds": [{ + "protocol": "freedom", + "settings": {} + }] +} \ No newline at end of file diff --git a/docker/xray/xray.sh b/docker/xray/xray.sh new file mode 100644 index 0000000..8107916 --- /dev/null +++ b/docker/xray/xray.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# +# This is a Shell script for xray based alpine with Docker image +# +# Copyright (C) 2019 - 2020 Teddysun +# +# Reference URL: +# https://github.com/XTLS/Xray-core + +PLATFORM=$1 +if [ -z "$PLATFORM" ]; then + ARCH="amd64" +else + case "$PLATFORM" in + linux/386) + ARCH="386" + ;; + linux/amd64) + ARCH="amd64" + ;; + linux/arm/v6) + ARCH="arm6" + ;; + linux/arm/v7) + ARCH="arm7" + ;; + linux/arm64|linux/arm64/v8) + ARCH="arm64" + ;; + linux/ppc64le) + ARCH="ppc64le" + ;; + linux/s390x) + ARCH="s390x" + ;; + *) + ARCH="" + ;; + esac +fi +[ -z "${ARCH}" ] && echo "Error: Not supported OS Architecture" && exit 1 +# Download binary file +XRAY_FILE="xray_linux_${ARCH}" + +echo "Downloading binary file: ${XRAY_FILE}" +wget -O /usr/bin/xray https://dl.lamp.sh/files/${XRAY_FILE} > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: Failed to download binary file: ${XRAY_FILE}" && exit 1 +fi +echo "Download binary file: ${XRAY_FILE} completed" + +chmod +x /usr/bin/xray