
Estou encontrando um problema de rede desconcertante que me deixa coçando a cabeça. A situação é a seguinte: não consigo acessar as portas 80 e 433 de fora, mas posso encaminhar qualquer outra porta dentro do Docker e funciona perfeitamente! Configurei o UFW e também instalei o K3s, mas a maior parte dos meus serviços é executada usando o Docker Compose.
Para investigar mais, lancei um contêiner de teste Nginx e as coisas ficaram ainda mais estranhas.
Posso acessar esse contêiner de teste usando seu IP interno do Docker, mas mesmo um simples curl -I 127.0.0.1
resultado resulta em um erro 404:
-> # curl -I 127.0.0.1
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Wed, 20 Sep 2023 00:39:26 GMT
Content-Length: 19
A trama se complica quando descubro que posso acessá-lo de outro IP interno (uma rede VPN):
-> # curl -I 192.168.10.1
HTTP/1.1 200 OK
Server: nginx/1.25.2
Date: Wed, 20 Sep 2023 00:41:32 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 15 Aug 2023 17:03:04 GMT
Connection: keep-alive
ETag: "64dbafc8-267"
Accept-Ranges: bytes
Mas aqui está o problema: quando eu parar o contêiner, você esperaria ver um erro como este:
-> # curl -I 127.0.0.1
curl: (7) Failed to connect to 127.0.0.1 port 80 after 0 ms: Couldn't connect to server
No entanto, não, sou recebido com o mesmo erro 404 persistente!
ATUALIZAR:Para aumentar o mistério, quando desligo o contêiner do Docker, a tentativa de acesso 192.168.10.1
também resulta em um erro 404:
-> # curl -I 192.168.10.1
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Wed, 20 Sep 2023 00:51:49 GMT
Content-Length: 19
Estou completamente perplexo e não tenho ideia de onde o problema está se originando. Para tornar as coisas ainda mais confusas, posso repetir esta experiência com a porta 81 e tudo funciona conforme o esperado. Se alguém tiver alguma ideia ou sugestão sobre como depurar isso, agradeceria muito sua ajuda!
Aqui estão algumas outras saídas:
-> # lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 9815 root 4u IPv4 54638 0t0 TCP *:http (LISTEN)
docker-pr 9823 root 4u IPv6 48079 0t0 TCP *:http (LISTEN)
-> # docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
975e74d4bdfd nginx:latest "/docker-entrypoint.…" 29 minutes ago Up 29 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp nginx_test_nginx-test_1
-> # ufw status
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
443 ALLOW Anywhere
Anywhere ALLOW 192.168.1.0/24
Anywhere ALLOW 192.168.178.0/24
81/tcp ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
443 (v6) ALLOW Anywhere (v6)
81/tcp (v6) ALLOW Anywhere (v6)
Anywhere on eth0 ALLOW FWD Anywhere on wghub
Anywhere on wghub ALLOW FWD Anywhere on wghub
Anywhere (v6) on eth0 ALLOW FWD Anywhere (v6) on wghub
Anywhere (v6) on wghub ALLOW FWD Anywhere (v6) on wghub
-> # netstat -ltnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:10010 0.0.0.0:* LISTEN 1374/containerd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 631/sshd: /usr/sbin
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9815/docker-proxy
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 610/systemd-resolve
tcp6 0 0 :::22 :::* LISTEN 631/sshd: /usr/sbin
tcp6 0 0 :::80 :::* LISTEN 9823/docker-proxy
-> # cat /etc/default/docker
DOCKER_OPTS="--iptables=false"
ATUALIZAR:Esta é minha configuração de teste:
docker-compose.yml
version: '3'
services:
nginx-test:
image: nginx:latest
ports:
- "80:80"