| #--- PREREQS: | |
| # - to prep wkg dir: ./_env_config/local_dev/utl_prep_localUnitTest.sh | |
| # - to backup wkg dir: ./_env_config/local_dev/utl_prep_localUnitTest.sh --backup | |
| # - to build dkr image: make sure you stop and remove the container if you are replacing/upgrading; | |
| # or change the version tag# from 0.0.1 | |
| #--- DOCKER: | |
| # docker build -t img_fastapi_templ:0.0.1 . | |
| # docker create -it -p 7860:7860 --name ctr_fastapi_templ img_fastapi_templ:0.0.1 | |
| # docker start -it ctr_fastapi_templ | |
| # docker run -it -p 7860:7860 --name ctr_fastapi_templ img_fastapi_templ:0.0.1 | |
| # docker push kidcoconut73/<img:tag> | |
| #--- use a base image of python | |
| FROM python:3.8-slim-buster | |
| # Set up a new user named "user" with user ID 1000 | |
| USER root | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| #--- set docker image working directory to /app | |
| RUN mkdir $HOME/app $HOME/app/scripts | |
| WORKDIR $HOME/app | |
| #--- install all lib dependencies into the image | |
| COPY --chown=user ./requirements.txt ./requirements.txt | |
| RUN pip install --no-cache-dir -r ./requirements.txt | |
| #--- copy files from the local pwd to the docker image /app folder | |
| #--- .dockerignore: ensure no local data folders or files (images) are copied into the docker image/container | |
| COPY --chown=user ./_env_config/local_dev/utl_dkr_preRun.sh ./scripts/docker/ | |
| COPY --chown=user ./fastapi ./fastapi | |
| COPY --chown=user ./streamlit ./streamlit | |
| #--- for huggingface; assume 1:1 mapping between internal and external ports; and only one port can truly be exposed | |
| #--- for fastapi; external 7860; internal 7860 | |
| #--- for streamlit; external xxxxx; internal 39131 | |
| EXPOSE 7860 | |
| #--- establish environment prereqs | |
| ENTRYPOINT [ "./scripts/docker/utl_dkr_preRun.sh" ] | |
| #--- WORKAROUND: you may have to stop the docker container through docker desktop, or cmd line eg docker kill <ctr_name> | |