Answer the question
In order to leave comments, you need to log in
How to properly configure docker-compose to access a site on FastAPI from a browser?
Help set up Docker containers.
In one MongoDB, in another site on FastAPI and Uvicorn server.
The docker-compose up -d command works fine.
If you enter the container and request 127.0.0.1:8000 with curl, then there is a response from the server.
Can't login from browser. CURL 127.0.0.1:8000 returns: curl: (56) Recv failure: Connection reset by
peer
Dockerfile
FROM python:3.8.7-buster
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
# don't create .pyc files.
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN pip install --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt
# copy project
COPY . /usr/src/app/
RUN cd /usr/src/app/
version: '3.8'
services:
mongodb:
command: mongod --noauth --port 27017
container_name: mongodb
environment:
- MONGO_INITDB_DATABASE=phrase-fastapi-mongodb
image: mongo:4.4.5-bionic
ports:
- "27017:27017"
volumes:
- .:/usr/src/app/
web:
build: .
command: uvicorn main:famd_app
container_name: web
ports:
- "8000:8000"
volumes:
- .:/usr/src/app/
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question