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.txt
file to specify its dependencies - listens on port
8080
- either has a
main.py
script 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
/env
directory in the container - Fetch the dependencies listed in
requirements.txt
into the virtualenv usingpip install
and leverage docker caching appropriately - Copy the application sources under the
/app
directory in the container