Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
FastAPI listen to outbound port

I have a FastAPI docker running on my debian 9 server with --net=host running on port 8000. I would like to make the FastAPI service open to the public, but do not know really how. I can do curl localost:8000/test and will see the return but when I do curl domain:8000/test it will respond connection refused.

I have opened the port sudo iptables -A INPUT -p tcp --dport 8000 -j ACCEPT but still not seeing anything. Do I have to configure uvicorn somehow to resolve the domain internally, similar to what apache does with virtual hosts?

netstat -tulpn
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
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:8000          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
sudo ss -tulpn                                                    
Netid State      Recv-Q Send-Q Local Address:Port                Peer Address:Port
tcp   LISTEN     0      128        127.0.0.1:8000                           *:*                   users:(("gunicorn",pid=44998,fd=5),("gunicorn",pid=44983,fd=5))

or should this rather return 0.0.0.0:8000 because I can ssh into the host no problem?

Dockerfile

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9-alpine3.14

COPY ./app /app

USER root

COPY ./requirements.txt /requirements.txt
RUN apk add py3-pip && \
    pip install --upgrade pip

RUN apk add --no-cache mariadb-connector-c-dev ;\
    apk add --no-cache --virtual .build-deps \
        build-base \
        mariadb-dev ;\
    pip install -r /requirements.txt;\
    apk del .build-deps 

ENV HOSTNAME fastapi
ENV PYTHONPATH '/:/app'
COPY ./gunicorn_conf.py /gunicorn_conf.py
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

since you can access FastAPI from your host machine, that means docker port mapping works just fine. what is left is to add the hostname to the origins in the Router.py module something like this \

origins = [
    "http://127.0.0.1:8000",
    "http://localhost:8000",
    "http://yourhostgoeshere:yourport",

]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

remember to change HTTP to HTTPS if you don't have a proxy.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda