no puedo acceder a localhost desde el contenedor Docker

no puedo acceder a localhost desde el contenedor Docker

Seguí este tutorial paso a paso:https://www.youtube.com/watch?v=NZGu-9KQVsE

  • Creé un Dockerfile:

DESDE ubuntu:jammy

RUN : \
    && apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt-get install -y \
        curl \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
  • Construí la imagen de la ventana acoplable:
docker build -t mycurl .
  • Ejecuté la imagen usando
docker run --add-host host.docker.internal:host-gateway --rm -ti mycurl bash
  • Comencé un servidor local usando
python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
  • Pero cuando intento acceder desde mi contenedor, obtengo este tiempo de espera:
root@da4d8b1f4ae4:/# curl host.docker.internal:8000
curl: (28) Failed to connect to host.docker.internal port 8000 after 133451 ms: Connection timed out

Mi /etc/hosts es:

root@da4d8b1f4ae4:/# cat /etc/hosts
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.1  host.docker.internal
172.17.0.2  da4d8b1f4ae4

¿Alguna idea de por qué? Estoy en Ubuntu 22.04.4 LTS

Respuesta1

Resolví mi problema ejecutando esto:

sudo ufw allow 8000

información relacionada