Skip to content

Latest commit

 

History

History
 
 

example2

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Dockerize a Python web app

1. Create the app locally

$ python3 -m venv venv
$ . venv/bin/activate
$ pip install fastapi uvicorn

Try it:

$ uvicorn app.main:app --port 80

Save dependencies:

$ pip freeze > requirements.txt

2. Build the Docker image

$ docker build -t fastapi-image . 

Note that we use a .dockerignore file to ignore certain files/folders.

3. Run the Docker image

Normal:

$ docker run -p 80:80 fastapi-image

Run 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").