From ffa2f496211da1fbc21b9474cbfd75e4ca5690c0 Mon Sep 17 00:00:00 2001 From: adoot Date: Fri, 25 Dec 2015 02:27:13 +0000 Subject: [PATCH] add: docker file --- contrib/docker/Dockerfile | 23 +++++++++++++++++++++++ contrib/docker/README.md | 26 ++++++++++++++++++++++++++ contrib/docker/build.sh | 7 +++++++ contrib/docker/gen-server-cfg.sh | 30 ++++++++++++++++++++++++++++++ contrib/docker/run.sh | 3 +++ 5 files changed, 89 insertions(+) create mode 100644 contrib/docker/Dockerfile create mode 100644 contrib/docker/README.md create mode 100755 contrib/docker/build.sh create mode 100755 contrib/docker/gen-server-cfg.sh create mode 100755 contrib/docker/run.sh diff --git a/contrib/docker/Dockerfile b/contrib/docker/Dockerfile new file mode 100644 index 00000000..89c8ac96 --- /dev/null +++ b/contrib/docker/Dockerfile @@ -0,0 +1,23 @@ +FROM phusion/baseimage + +ENV GOPATH /v2ray +ENV PATH $PATH:/usr/local/go/bin + +RUN apt-get update +RUN apt-get install -y git +RUN apt-get clean + +RUN mkdir -p /v2ray/logs +RUN curl -o /go.tar.gz https://storage.googleapis.com/golang/go1.5.2.linux-amd64.tar.gz +RUN tar -C /usr/local -xzf /go.tar.gz +RUN rm /go.tar.gz + + +RUN go get -u github.com/v2ray/v2ray-core +RUN rm -f $GOPATH/bin/build +RUN go install github.com/v2ray/v2ray-core/tools/build +RUN $GOPATH/bin/build + +EXPOSE 27183 +ADD server-cfg.json /v2ray/server-cfg.json +CMD /v2ray/bin/v2ray-custom-linux-64/v2ray --config="/v2ray/server-cfg.json" diff --git a/contrib/docker/README.md b/contrib/docker/README.md new file mode 100644 index 00000000..69401a7b --- /dev/null +++ b/contrib/docker/README.md @@ -0,0 +1,26 @@ +Docker build for v2ray +======================= + +Usage +----- + +To build the image: + +```bash +./build.sh +``` + +Then spin up a v2ray instance with: + +```bash +./run.sh +``` + +The build script will generate a server config file with random user id. You +can get it from `server-cfg.json`. + +To tail the access log, run: + +```bash +docker exec v2ray tail -F /v2ray/logs/access.log +``` diff --git a/contrib/docker/build.sh b/contrib/docker/build.sh new file mode 100755 index 00000000..677b15b6 --- /dev/null +++ b/contrib/docker/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [ ! -e server-cfg.json ]; then + ./gen-server-config.sh +fi + +docker build --rm=true --tag=$USER/v2ray ./ diff --git a/contrib/docker/gen-server-cfg.sh b/contrib/docker/gen-server-cfg.sh new file mode 100755 index 00000000..5cd861d5 --- /dev/null +++ b/contrib/docker/gen-server-cfg.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +PORT=27183 + +rand_str () { + cat /dev/urandom | tr -dc 'a-f0-9' | fold -w $1 | head -n 1 +} + +ID="$(rand_str 8)-$(rand_str 4)-$(rand_str 4)-$(rand_str 4)-$(rand_str 12)" + +cat < server-cfg.json +{ + "port": $PORT, + "log" : { + "access": "/v2ray/logs/access.log" + }, + "inbound": { + "protocol": "vmess", + "settings": { + "clients": [ + {"id": "$ID"} + ] + } + }, + "outbound": { + "protocol": "freedom", + "settings": {} + } +} +EOF diff --git a/contrib/docker/run.sh b/contrib/docker/run.sh new file mode 100755 index 00000000..4a85340a --- /dev/null +++ b/contrib/docker/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker run -d --name=v2ray -p 27183:27183/tcp $USER/v2ray