One single Docker image to automatically deploy and run any Python app on Docker
1.9K
šš³ A Docker image that downloads a Git repository with a Python app you want to deploy when the container runs for the first time
Run a Python app that is hosted on any Git repository, without having to create a specific Docker image for that project and version.
This means that one single image let you run any(1) Python project, without having to build one image per project. The latest/wanted version of that project is cloned during the first execution of the container trough Git. Any update on the project can be downloaded by just rebuilding the container.
(1) The project must follow a structure in order for the entrypoint to run it (see Python Project structureā ).
When you create a new container and properly set the Git URL (using the GIT_REPOSITORY ENV), during the first execution
the entrypoint script will clone the repository in your container, install all the Python requirements through pip,
and start it. After this first startup, the next time/s the container starts, the setup process is skipped.
App runs with a new user created on Dockerbuild (appuser by default), so the app won't run with root privileges.
docker run -d -e GIT_REPOSITORY=<url to a Git repository> --name <containerName> davidlor/python-autoclonable-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: MyApp)USERNAME: name of the user that is created on Dockerbuild to run the app with (optional, default: appuser)IMAGE_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 entrypoint script expects the cloned Python app to have the following structure:
ProjectRoot (cloned through Git)
ā- __main__.py
|- requirements.txt (if required)
ā- ...and all the other project files/directories
Some examples of projects compliant with this structure are:
latest, slim and alpine of the base Python image,
on each push on the master branch.develop branch triggers a new image with the sufix -devIf you want to build this image (required in order to change default username or base image tag), you must do on host machine:
USERNAME ARGIMAGE_TAG ARG (example: alpine or slim)git clone https://github.com/David-Lor/Docker-Python-Autoclonable-App.git DockerPythonApp
docker build DockerPythonApp --build-arg USERNAME=<desiredUser> --build-arg IMAGE_TAG=<baseTag> -t yourname/yourtag:yourversion
docker run [...] yourname/yourtag:yourversion
Content type
Image
Digest
Size
333.1 MB
Last updated
almost 7 years ago
docker pull davidlor/python-autoclonable-app