mongodb-labs / full-stack-fastapi-mongodb

Full stack, modern web application generator. Using FastAPI, MongoDB as database, Docker, automatic HTTPS and more.
MIT License
510 stars 86 forks source link

Recommended way to run the docker-compose #44

Open Mrostgaard opened 6 months ago

Mrostgaard commented 6 months ago

I've been trying for a few days to run this project, but without success. I would prefer not to run this as root as that seems unnecessary.

When i run it from a fresh cookiecutter output i get:

❯ docker-compose up -d
[+] Running 6/9
 ⠴ Network project_traefik-public    Created                                                                                                                         1.6s
 ⠴ Network project_default           Created                                                                                                                         1.5s
 ✔ Container project-backend-1       Started                                                                                                                         1.5s
 ✔ Container project-mongodb-1       Started                                                                                                                         1.5s
 ✔ Container project-celeryworker-1  Started                                                                                                                         0.8s
 ✔ Container project-flower-1        Started                                                                                                                         1.5s
 ⠼ Container project-proxy-1         Starting                                                                                                                        1.5s
 ✔ Container project-frontend-1      Started                                                                                                                         0.9s
 ✔ Container project-queue-1         Started                                                                                                                         0.9s

Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:80 -> 0.0.0.0:0: listen tcp 0.0.0.0:80: bind: permission denied

I've tried a ton of things, remapping '8888:80' etc etc which didn't accomplish the things I wanted it to do. I would still prefer to serve backend at 'localhost/api' Adding

 cap_add:
      - CAP_NET_BIND_SERVICE

doesn't help at all. Still same message. The only thing I can think of is to assign the privileges to the docker process for cap_net_bind_service (I haven't tried this yet) or running the docker-compose up -d as root. Both solutions doesn't seem optimal, especially when I need it to run on a production service. Would prefer that the process or the user running it doesn't have elevated privileges.

If the best way is just to run traefik on 8080 and then bind the backend to 8080 (or something similar) and then run the change .env in frontend to: NEXT_PUBLIC_API_URL=http://localhost:8080/api/v1

I'm pretty new to docker, so there might be a obvious solution to this, but googling and ChatGPT hasn't been able to help me

EDIT: I tried updating the docker-compose.override.yml to look like this:

version: "3.7"
services:
  proxy:
    ports:
      # - "80:80"  # Removed this
      - "8090:8080"
    command:
      -------
  backend:
    ports:
      - "8888:80" # changed from "8888:8888" --> "8888:80"

This seem to work, I still can't access anything when visiting: http://localhost:8888/api/ It just returns: image

same for http://localhost:8888/api/v1

but when I use the frontend (after updating .env.local to localhost:8888) I get a response from the server: {"access_token":"**********","refresh_token":"**********","token_type":"bearer"} I didn't change the access_token or refresh_token, they came like that, I don't know if that's what's supposed to be?

I've also tested with a wrong password and that doesn't pass validation, so the authentication is happening on the backend with a connection to the database.

EDIT 2: I found the correct urls for the documentation by just thinking a little, so I have access to the documentation on 127.0.0.1:8888/docs / redoc But the main question still stands regarding running port 80 in docker

Jibola commented 5 months ago

Hey @Mrostgaard, we'll take a look at this. Hope to provide you a solution soon.