Eu quero configurar dois contêineres via docker-compose de uma maneira, então um é o cliente OpenVPN, e outro é o proxy HTTP do Squid, expondo a porta 3128 para acessar esse túnel de fora.
Agora, o problema é que, por algum motivo, os pedidos ao Squid demoram exatamente 30 segundos para entrar no container.
Comecei a investigar o problema e parece que ele só é reproduzido quando o túnel VPN está conectado, E a porta exposta está localizada em outro contêiner.
O servidor da web de exemplo (simulando o Squid) está escutando na porta 8080. Agora estou cronometrando o pedido:
$ time { curl http://127.0.0.1:8080; }
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>
<title>Directory listing for /</title>
<body>
<h2>Directory listing for /</h2>
<hr>
<ul>
</ul>
<hr>
</body>
</html>
real 0m30.066s
user 0m0.005s
sys 0m0.011s
Por algum motivo, leva 30 segundos para o pacote chegar dentro do contêiner. Colocar o servidor da web dentro do mesmo contêiner com o OpenVPN resolve o problema. Evitar que o OpenVPN se conecte "resolve" o problema. Isso se reproduz no Docker para Mac e no Docker CE instalado na máquina virtual do Ubuntu.
Também há uma pergunta semelhante, mas infelizmente sem resposta:
Para sua conveniência, estou fornecendo uma configuração completa de trabalho para reproduzir:
docker-compose.yml
version: "3.3"
services:
vpn:
build: ./vpn
cap_add:
- net_admin
devices:
- /dev/net/tun
restart: unless-stopped
ports:
- "8080:8080"
web:
image: trinitronx/python-simplehttpserver
depends_on:
- vpn
network_mode: "service:vpn"
restart: unless-stopped
vpn / Dockerfile
FROM dperson/openvpn-client
COPY vpn.conf /vpn/vpn.conf
COPY creds.txt /vpn/creds.txt
vpn / vpn.conf
client
dev tun
proto tcp
remote 176.126.237.217 443
remote euro217.vpnbook.com 443
resolv-retry infinite
nobind
persist-key
persist-tun
auth-user-pass /vpn/creds.txt
comp-lzo
verb 3
cipher AES-128-CBC
fast-io
pull
route-delay 2
redirect-gateway
<ca>
-----BEGIN CERTIFICATE-----
MIIDyzCCAzSgAwIBAgIJAKRtpjsIvek1MA0GCSqGSIb3DQEBBQUAMIGgMQswCQYD
VQ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Y4fo
ct2Ii5uMzwERRvHjJ7yzJJic8gkEca2adQJABxjZj4JV8DBCN3kLtlQFfMfnLhPd
9NFxTusGuvY9fM7GrXXKSMuqLwO9ZkxRHNIJsIz2N20Kt76+e1CmzUdS4QJAVvbQ
WKUgHBMRcI2s3PecuOmQspxG+D+UR3kpVBYs9F2aEZIEBuCfLuIW9Mcfd2I2NjyY
4NDSSYp1adAh/pdhVQJBANDrlnodYDu6A+a4YO9otjd+296/T8JpePI/KNxk7N0A
gm7SAhk379I6hr5NXdBbvTedlb1ULrhWV8lpwZ9HW2k=
-----END RSA PRIVATE KEY-----
</key>
vpn / creds.txt
vpnbook
5f39ntx