google/python-runtime is a docker base image that makes it easy to dockerize standard Python application.
It can automatically bundle a Python application and its dependencies with a single line Dockerfile.
It is based on google/python base image.
-
Create a Dockerfile in your python application directory with the following content:
FROM google/python-runtime -
Run the following command in your application directory:
docker build -t app .
See the sources for google/python-hello based on this image.
The image assumes that your application:
- has a
requirements.txtfile to specify its dependencies - listens on port
8080 - either has a
main.pyscript as entrypoint or definesENTRYPOINT ["/env/bin/python", "/app/some_other_file.py"]in itsDockerfile
When building your application docker image, ONBUILD triggers:
- Create a new virtualenv under the
/envdirectory in the container - Fetch the dependencies listed in
requirements.txtinto the virtualenv usingpip installand leverage docker caching appropriately - Copy the application sources under the
/appdirectory in the container