diff --git a/Dockerfile b/Dockerfile index c8d4b10..e302793 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ FROM alpine RUN apk add --no-cache socat +VOLUME ["/local", "/tmp/out"] +COPY helpers /local/helpers ENTRYPOINT ["socat"] diff --git a/docker-compose.yml b/docker-compose.yml index 32c19c1..0a167fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,26 +1,44 @@ version: '2' services: - - proxy: - build: . - ports: - - "127.0.0.1:13194:13194" - #- "127.0.0.1:13194:13194/udp" - # UDP did not work, probably because the source port changes all the time - #command: -v UDP4-RECVFROM:13194,fork UDP4-SENDTO:172.17.0.1:1194 - command: TCP-LISTEN:13194,fork TCP:172.17.0.1:1194 + proxy: + image: tkaefer/docker-mac-network + ports: + - "127.0.0.1:13194:13194" + #- "127.0.0.1:13194:13194/udp" + # UDP did not work, probably because the source port changes all the time + volumes: + - ./out:/tmp/out + #command: -v UDP4-RECVFROM:13194,fork UDP4-SENDTO:172.17.0.1:1194 + command: TCP-LISTEN:13194,fork TCP:10.64.1.2:1194 + environment: + - FORWARD_PORT=13194 + networks: + backend: - openvpn: - image: kylemanna/openvpn - volumes: - - .:/local - - ./config:/etc/openvpn - network_mode: host - cap_add: - - NET_ADMIN - environment: - dest: docker-for-mac.ovpn - DEBUG: '1' - command: /local/helpers/run.sh + openvpn: + image: kylemanna/openvpn + volumes_from: + - proxy + volumes: + - ./config:/etc/openvpn + cap_add: + - NET_ADMIN + environment: + dest: docker-for-mac.ovpn + DEBUG: '1' + DOCKER_NETWORK: 10.64.1.0 + DOCKER_NETMASK: 255.255.255.192 + command: /local/helpers/run.sh + networks: + backend: + ipv4_address: 10.64.1.2 +networks: + backend: + driver: bridge + ipam: + driver: default + config: + - subnet: 10.64.1.0/26 + gateway: 10.64.1.1 diff --git a/helpers/run.sh b/helpers/run.sh index 863ae5e..5e386c7 100755 --- a/helpers/run.sh +++ b/helpers/run.sh @@ -1,8 +1,13 @@ #!/bin/sh dest=${dest:-docker.ovpn} +network=${DOCKER_NETWORK:-172.16.0.0} +netmask=${DOCKER_NETMASK:-255.240.0.0} +forward_port=${FORWARD_PORT:-13194} -if [ ! -f "/local/$dest" ]; then +OUT_BASE="/tmp/out" + +if [ ! -f "${OUT_BASE}/$dest" ]; then echo "*** REGENERATING ALL CONFIGS ***" set -ex #rm -rf /etc/openvpn/* @@ -10,10 +15,7 @@ if [ ! -f "/local/$dest" ]; then sed -i 's|^push|#push|' /etc/openvpn/openvpn.conf echo localhost | ovpn_initpki nopass easyrsa build-client-full host nopass - ovpn_getclient host | sed ' - s|localhost 1194|localhost 13194|; - s|redirect-gateway.*|route 172.16.0.0 255.240.0.0|; - ' > "/local/$dest" + ovpn_getclient host | sed "s|localhost 1194|localhost ${forward_port}|;s|redirect-gateway.*|route ${network} ${netmask}|;" > "${OUT_BASE}/$dest" fi exec ovpn_run