A base Python 3.10 Slim FAPI image1 for basing projects available at EWC Docker Hub.
The following pip dependencies are already installed.
fastapiuvicorn
Note that the py-fapi-31-slim is the Docker Compose Service to Build.
There is a build script included that uses the local .env file & an Evil Wizard Creations Protocol that makes this much simpler.
build-up-py-fapi-31-slim.shAlternatively there is the full Procedure.
-
Build the Image using the
docker-compose-build.yamlconfiguration.docker-compose -f ./docker-compose-build.yaml build --no-cache py-fapi-31-slim
-
Compose Up using the
docker-compose-build.yamlconfiguration will use the new built Image and-dto detach.docker-compose -f ./docker-compose-build.yaml up -d
Build the Docker Image without using cached versions of previous image build stages.
sudo docker build \
-f py-fapi-31-slim.Dockerfile \
--target build-py-fapi-31-slim \
--build-arg APP_ENV=local \
--no-cache \
-t py-fapi-31-slim:latest \
.N.B.
-
Using
-f py-fapi-31-slim.DockerfileTo specify the filename to build otherwise it is expected to be named
Dockerfile. -
Using
--target build-py-fapi-31-slimTo select the build target stage2 from the Dockerfile.
-
Using
--build-arg ARG=valueTo set build argument values to use.
This creates a named container and attaches it to the host network and may cause port conflict if the host machine is already listening on any exposed ports from the Docker Image being used.
sudo docker run \
-d \
--network host \
-v "$(pwd)"/public_html:/code/src \
--name py-fapi-31-slim \
py-fapi-31-slim:latestOR
This creates a named container and attaches it to the bridge network and allows for port forward mapping from the host to the Container.
sudo docker run \
-d \
--network bridge \
-p 8080:80/tcp \
-v "$(pwd)"/src:/code/src \
--name py-fapi-31-slim \
py-fapi-31-slim:latestN.B.
-
Using
-v "$(pwd)"/src:/code/srcTo Volume Mount the folder
srcfrom the current folder to/code/srcon the running container. It is where Python FAPI serves the content from & allows for realtime change updates. -
Using
-p 8080:80/tcpTo map port 8080 on the Host machine to port 80 on the Container using the bridge network.
-
Using
--name py-fapi-31-slimTo name the Container being created.
sudo docker start py-fapi-31-slimsudo docker stop py-fapi-31-slimsudo docker exec -it py-fapi-31-slim /bin/bashThis Image is intended for Development purpose only & to use as a learning aid. DO NOT use this anywhere near a Production environment.