Skip to content

itaru2622/docker-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple usage on linux:

docker run --rm -it -p 8000:8000 -v ${PWD}:/app itaru2622/fastapi:bookworm

# the above cmd start docker container  with:
apt  install -y /app/requirements-apt.txt
pip3 install -r /app/requirements.txt
uvicorn main:app 

other usage on linux:

you can:

  • set any uvicorn options by opts environment variable.
  • change app name by app environment according to your implementation
  • change requirement file path for apt install by apt_requirements environment variable.
  • change requirement file path for pip install by py_requirements environment variable.
  • change upgrade strategy for pip install by pip_install_opt environment variable.
  • use your own start.sh (boot up script) to full control boot procedure. in below case, ${PWD}/start.sh or ${PWD}/bin/start.sh if exists and it is executable.
docker run --rm -it -p 8000:8000 -v ${PWD}:${PWD} -w ${PWD} -e py_requirements=${PWD}/requirements.txt -e pip_install_opt='--upgrade --upgrade-strategy eager' -e apt_requirements=${PWD}/requirements-apt.txt -e app=main:app -e opts='--host 0.0.0.0 --reload --reload-include "*.py" --reload-include "*.conf"' itaru2622/fastapi:bookworm
#
# the above cmd starts docker container via (/usr/local/bin/)start.sh with:
#
apt  install -y ${apt_requirements}
pip3 install -r ${py_requirements} ${pip_install_opt}
uvicorn ${opts} ${app}

build docker image

docker build --build-arg base=python:3-bookworm --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} -t itaru2622/fastapi:bookworm .