From 43099d6800a9f318f89236ea311b3648ac16faae Mon Sep 17 00:00:00 2001 From: Kristian Haugene Date: Fri, 13 May 2016 23:51:47 +0200 Subject: [PATCH] Made proxy container with templated config --- docker-compose.yml | 19 ++++++++++--------- proxy/Dockerfile | 14 ++++++++++++++ proxy/nginx.tmpl | 23 +++++++++++++++++++++++ 3 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 proxy/Dockerfile create mode 100644 proxy/nginx.tmpl diff --git a/docker-compose.yml b/docker-compose.yml index a6a61bea8..19423b295 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,9 @@ -openvpn: +transmission: image: haugene/transmission-openvpn privileged: true - ports: - - "9091:9091" + dns: + - 8.8.8.8 + - 8.8.4.4 volumes: - /etc/localtime:/etc/localtime:ro - /your/storage/path/:/data @@ -11,13 +12,13 @@ openvpn: OPENVPN_USERNAME: username OPENVPN_PASSWORD: password - -nginx: - image: library/nginx +proxy: + image: haugene/transmission-openvpn-proxy links: - - openvpn + - transmission ports: - - "8080:8080" + - 8080:8080 volumes: - /etc/localtime:/etc/localtime:ro - - /path/to/nginx.conf:/etc/nginx/nginx.conf:ro + environment: + PORT: 8080 diff --git a/proxy/Dockerfile b/proxy/Dockerfile new file mode 100644 index 000000000..56c3cef99 --- /dev/null +++ b/proxy/Dockerfile @@ -0,0 +1,14 @@ +FROM nginx + +# Get curl and dockerize +RUN apt-get update \ + && apt-get install -y curl \ + && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ + && curl -L https://github.com/jwilder/dockerize/releases/download/v0.2.0/dockerize-linux-amd64-v0.2.0.tar.gz | tar -C /usr/local/bin -xzv + +# Set default Transmission port and copy config template +ENV TRANSMISSION_PORT=9091 +COPY nginx.tmpl /etc/nginx/nginx.tmpl + +# Run nginx after dockerizing config +CMD [ "dockerize", "-template", "/etc/nginx/nginx.tmpl:/etc/nginx/nginx.conf", "nginx", "-g", "daemon off;" ] \ No newline at end of file diff --git a/proxy/nginx.tmpl b/proxy/nginx.tmpl new file mode 100644 index 000000000..9a6c0b481 --- /dev/null +++ b/proxy/nginx.tmpl @@ -0,0 +1,23 @@ +events { + worker_connections 1024; +} + +http { + + server { + listen {{ .Env.PORT }}; + + location / { + proxy_pass http://transmission:{{ .Env.TRANSMISSION_PORT }}; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # HTTP 1.1 support + proxy_http_version 1.1; + proxy_set_header Connection ""; + } + } + +} \ No newline at end of file