M
M
multiscripter2021-04-14 20:34:55
Docker
multiscripter, 2021-04-14 20:34:55

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/


docker-compose.yml
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

2 answer(s)
D
Dmitry, 2021-04-14
@q2digger

I don't see the EXPOSED directive in the dockerfile.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question