Deploy a Python app from a Git repository, to avoid building a Docker image for each app
50K+
A Docker image to deploy a Python app from a Git repository, to avoid building a Docker image for each app. The container will handle the git clone and requirements installing before the app starts for the first time.
requirements.txt fileThe entrypoint script expects the cloned repository to have the following structure:
ProjectRoot (cloned through Git)
│- __main__.py (app entrypoint that will run)
|- requirements.txt (if required)
│- ...and all the other project files/directories
Some examples of projects compliant with this structure are:
docker run -e GIT_REPOSITORY="https://github.com/David-Lor/Python-HelloWorld.git" davidlor/python-git-app
GIT_REPOSITORY: URL of the remote Git repository to get the app from (required)GIT_BRANCH: set the Branch to clone from the Git repository (optional, default: use default branch)APP_NAME: name of your app. This name is given to the directory where project is cloned on(optional, default: PythonApp)USERNAME: name of the user that is created on Dockerbuild to run the app with (optional, default: user)BASE_TAG: tag of the Python base image to be used for the build (optional, default: latest)Only required variable is (ENV) GIT_REPOSITORY.
The variables marked with (ARG) are build-args.
The tags available for the image are a limited selection of tags used in the official Python image. The building and publishing of the images into DockerHub is performed by this Github Actions workflow, where the full list of supported tags is defined.
If you want to build this image (required in order to change default username, base image tag or building for unsupported architedtures), you must do on host machine:
USERNAME ARGBASE_TAG ARG (example: alpine or slim)git clone https://github.com/David-Lor/Docker-Python-Autoclonable-App.git DockerPythonClonable
docker build DockerPythonClonable --build-arg USERNAME=user --build-arg BASE_TAG=slim -t yourname/yourtag:yourversion
docker run [...] yourname/yourtag:yourversion
The steps that run when the container starts are:
make test - run tests (requires root/sudo & pytest)make test USE_SUDO=0 - run tests without sudo (if current user is root or part of docker group)make test-classic - run tests sequentially (make test runs in parallel using pytest-xdist)test-install-requirements - pip install test requirementssudo build BASE_TAG=slim - build the image with the python:slim base image, and tag as python-git-app:slimsudo build BASE_TAG=alpine IMAGE_TAG=my-python:latest - build the image with the python:alpine base image, and tag as my-python:latestbash to sh (Alpine compatibility)test-nobuild* rules in Makefileimage_tag param on testsIMAGE_TAG to IMAGE_NAME when refering to the full image name (name:tag)Content type
Image
Digest
sha256:d1d6d48a6…
Size
78.2 MB
Last updated
about 23 hours ago
Requires Docker Desktop 4.37.1 or later.