Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make proxy port configurable #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FROM alpine
RUN apk add --no-cache socat
VOLUME ["/local", "/tmp/out"]
COPY helpers /local/helpers
ENTRYPOINT ["socat"]
60 changes: 39 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions helpers/run.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/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/*
ovpn_genconfig -u tcp://localhost
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