$ python3 -m venv venv
$ . venv/bin/activate
$ pip install fastapi uvicornTry it:
$ uvicorn app.main:app --port 80Save dependencies:
$ pip freeze > requirements.txt$ docker build -t fastapi-image . Note that we use a .dockerignore file to ignore certain files/folders.
Normal:
$ docker run -p 80:80 fastapi-imageRun in background and give a name:
$ docker run -d --name myfastapicontainer -p 80:80 fastapi-image-p 80:80: Map the port from outside to the port from the container
Host in Dockerfile must be:
host: 0.0.0.0: "placeholder", it tells a server to listen for and accept connections from any IP address ("all IPv4 addresses on the local machine").