Python container with git pull/push (and re-pull on reboot) features
6.5K
This is a Dockerfile to build a container image for python, with the ability to push and pull source code to and from git (including an optional automatic git pull whenever the container is restarted).
The source files for this project can be found here: https://github.com/TheBoroer/docker-python
If you have any improvements please submit a pull request.
The Docker hub build can be found here: https://hub.docker.com/u/boro/python/
This repository uses Drone CI to automatically build and push multiple Python versions to Docker Hub. Every push to the main branch triggers builds for all supported Python versions.
main branchARG PYTHON_VERSION for multi-version supportboro/python)The build process uses Docker build arguments to dynamically select the Python base image version, ensuring all images have the same package set and configuration while supporting multiple Python versions.
.x means it'll use the latest patch version available at the time this image was built.
All images are built from the official Python Debian Slim images and include the same comprehensive package set for development and deployment.
Pull the latest Python 3.12 image:
docker pull boro/python:3.12
Or pull a specific Python version:
docker pull boro/python:3.11
docker pull boro/python:3.10
docker pull boro/python:3.9
View all available tags: https://hub.docker.com/r/boro/python/tags
To simply run the container with Python 3.12:
sudo docker run -d boro/python:3.12
Or run with a specific Python version:
sudo docker run -d boro/python:3.11
sudo docker run -d boro/python:2.7
To install modules/components for your python application to run simply include a requirements.txt file in the root of your application. The container will then install the components on start.
The following flags are a list of all the currently supported options that can be changed by passing in the variables to docker with the -e flag.
/app to your own setting$WORKDIR/scripts folderOne of the nice features of this container is its ability to pull code from a git repository with a couple of environmental variables passed at run time.
REQUIRED: To create a personal access token on Github follow this guide.
You can pass the container your personal access token from your git account using the GIT_PERSONAL_TOKEN flag. This token must be setup with the correct permissions in git in order to push and pull code.
Since the access token acts as a password with limited access, the git push/pull uses HTTPS to authenticate. You will need to specify your GIT_USERNAME and GIT_PERSONAL_TOKEN variables to push and pull. You'll need to also have the GIT_EMAIL, GIT_NAME and GIT_REPO common variables defined.
docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' boro/python:3.12
To pull a repository and specify a branch add the GIT_BRANCH environment variable:
docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' -e 'GIT_BRANCH=stage' boro/python:3.12
There is often an occasion where you need to run a bash script on code to do a transformation once code lands in the container. For this reason there's scripting support. By including a scripts folder in your git repository and passing the RUN_SCRIPTS=1 flag to your command line the container will execute your bash scripts after code is pulled via git.
Specify the GIT_EMAIL and GIT_NAME variables for this to work. They are used to set up git correctly and allow the following commands to work.
To push code changes made within the container back to git run:
sudo docker exec -t -i <CONTAINER_NAME> /usr/bin/push
In order to refresh the code in a container and pull newer code from git run:
sudo docker exec -t -i <CONTAINER_NAME> /usr/bin/pull
To set the variables pass them in as environment variables on the docker command line.
Example:
sudo docker run -d -e 'YOUR_VAR=VALUE' boro/python:3.12
All logs should now print out in stdout/stderr and are available via the docker logs command:
docker logs <CONTAINER_NAME>
You can set your workdir in the container to anything you want using the WORKDIR variable e.g -e "WORKDIR=/app/some/other/director". By default code is checked out into /app/ so if your git repository does not have code in the root you'll need to use this variable.
Content type
Image
Digest
sha256:903688473…
Size
259.1 MB
Last updated
12 months ago
docker pull boro/python:3.13