Changing port of Gunicorn Server with FastAPI in Docker context

  docker, fastapi, gunicorn, port

I use gunicorn to start my Webserver in Docker like this:

CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--reload", "-k", "uvicorn.workers.UvicornWorker", "app.main:app"]

I have a CLI Tool with should be able to overrule the port set in the Dockerfile:

@ runtime.command()
def run(branch: Optional[str] = "master", port: Optional[int] = 8000):

    subprocess.call(f"docker run -it -p 7000:7000 test", shell=True)

When I run this command, the Service is still running on port 8000, not on port 7000.

[2021-11-25 15:40:20 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2021-11-25 15:40:20 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
[2021-11-25 15:40:20 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2021-11-25 15:40:20 +0000] [11] [INFO] Booting worker with pid: 11
[2021-11-25 15:40:21 +0000] [11] [INFO] Started server process [11]
[2021-11-25 15:40:21 +0000] [11] [INFO] Waiting for application startup.

Is there a way to override the port which was set in my Dockerfile?

Source: Docker Questions

LEAVE A COMMENT