From c07cc6c6af5ff73e6086f8821699ea55777872a2 Mon Sep 17 00:00:00 2001 From: CzBiX Date: Mon, 22 Feb 2016 17:57:43 +0800 Subject: [PATCH 1/3] [docker] generate server config on first run --- tools/docker/Dockerfile | 16 ++++++++++------ tools/docker/README.md | 8 ++++++-- tools/docker/build.sh | 4 ---- tools/docker/docker-entrypoint.sh | 8 ++++++++ tools/docker/gen-server-cfg.sh | 1 + 5 files changed, 25 insertions(+), 12 deletions(-) create mode 100755 tools/docker/docker-entrypoint.sh diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index bd3dd32b9..a829585bd 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -1,10 +1,14 @@ FROM golang:latest -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 +RUN go get -u github.com/v2ray/v2ray-core \ + && rm -f $GOPATH/bin/build \ + && go install github.com/v2ray/v2ray-core/tools/build \ + && build \ + && rm -rf pkg src EXPOSE 27183 -ADD server-cfg.json /go/server-cfg.json -CMD /go/bin/v2ray-custom-linux-64/v2ray --config="/go/server-cfg.json" +COPY gen-server-cfg.sh /go/gen-server-cfg.sh +COPY docker-entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/go/bin/v2ray-custom-linux-64/v2ray", "--config=/go/server-cfg.json"] diff --git a/tools/docker/README.md b/tools/docker/README.md index 69401a7be..8594ddf68 100644 --- a/tools/docker/README.md +++ b/tools/docker/README.md @@ -16,8 +16,12 @@ Then spin up a v2ray instance with: ./run.sh ``` -The build script will generate a server config file with random user id. You -can get it from `server-cfg.json`. +The docker image will generate a server config file with random user id on first run. +You can get see it with: + +```bash +docker logs v2ray +``` To tail the access log, run: diff --git a/tools/docker/build.sh b/tools/docker/build.sh index 677b15b67..001d83254 100755 --- a/tools/docker/build.sh +++ b/tools/docker/build.sh @@ -1,7 +1,3 @@ #!/bin/bash -if [ ! -e server-cfg.json ]; then - ./gen-server-config.sh -fi - docker build --rm=true --tag=$USER/v2ray ./ diff --git a/tools/docker/docker-entrypoint.sh b/tools/docker/docker-entrypoint.sh new file mode 100755 index 000000000..db1a34277 --- /dev/null +++ b/tools/docker/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +if [ ! -e "server-cfg.json" ]; then + ./gen-server-cfg.sh +fi + +exec "$@" diff --git a/tools/docker/gen-server-cfg.sh b/tools/docker/gen-server-cfg.sh index 6974cd8a2..4886746d4 100755 --- a/tools/docker/gen-server-cfg.sh +++ b/tools/docker/gen-server-cfg.sh @@ -7,6 +7,7 @@ rand_str () { } ID="$(rand_str 8)-$(rand_str 4)-$(rand_str 4)-$(rand_str 4)-$(rand_str 12)" +echo "Generated client ID: $ID" cat < server-cfg.json { From c008f1f61462294878ff2b187f34f573543399a2 Mon Sep 17 00:00:00 2001 From: CzBiX Date: Mon, 22 Feb 2016 18:08:45 +0800 Subject: [PATCH 2/3] [doc] update readme for docker --- tools/docker/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/docker/README.md b/tools/docker/README.md index 8594ddf68..201a1476f 100644 --- a/tools/docker/README.md +++ b/tools/docker/README.md @@ -23,6 +23,12 @@ You can get see it with: docker logs v2ray ``` +You can also specify config file by manual with: + +```bash +docker run -d --name=v2ray -p 27183:27183 -v /config/file.json:/go/server-config.json $USER/v2ray +``` + To tail the access log, run: ```bash From 968f9b9d145268f6ba0fca0b33bdb953d5ac707e Mon Sep 17 00:00:00 2001 From: CzBiX Date: Mon, 22 Feb 2016 18:15:31 +0800 Subject: [PATCH 3/3] [doc] update logs file path missing in 6e84500 --- tools/docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker/README.md b/tools/docker/README.md index 201a1476f..1394193a4 100644 --- a/tools/docker/README.md +++ b/tools/docker/README.md @@ -32,5 +32,5 @@ docker run -d --name=v2ray -p 27183:27183 -v /config/file.json:/go/server-config To tail the access log, run: ```bash -docker exec v2ray tail -F /v2ray/logs/access.log +docker exec v2ray tail -F /go/access.log ```