Sign inSign up

sxmichael/python-runtime

By sxmichael

•Updated over 8 years ago

Image
0

2.1K

sxmichael/python-runtime repository overview

⁠Python runtime Dockerfile

This repository contains Dockerfile of Python⁠ runtime for Docker⁠'s automated build⁠ published to the public Docker Hub Registry⁠.

This image is a base image that makes it easy to dockerize standard Python⁠ application.

It can automatically bundle a Python application with its dependencies and set the default command with no additional Dockerfile instructions.

This project heavily borrowed code from Google's google/python-runtime⁠ Docker image.

⁠Base Docker Image
⁠Installation
  1. Install Docker⁠.

  2. Download automated build⁠ from public Docker Hub Registry⁠: docker pull dockerfile/python-runtime

    (alternatively, you can build an image from Dockerfile: docker build -t="dockerfile/python-runtime" github.com/dockerfile/python-runtime)

⁠Usage

This image assumes that your application:

  • has a apt-requirements.txt file to specify its system dependencies.
  • has a requirements.txt file to specify its dependencies.
  • either has a main.py script as entrypoint or defines CMD ["/env/bin/python", "/app/<custom-entry-file>.py"] in its Dockerfile.
  • listens on port 8080.

When building your application docker image, ONBUILD triggers:

  1. Create a new virtualenv under the /env directory in the container.
  2. Fetch the system dependencies listed in apt-requirements.txt using apt-get install -y and leverage docker caching appropriately.
  3. Fetch the dependencies listed in requirements.txt into the virtualenv using pip install and leverage docker caching appropriately.
  4. Copy the application sources under the /app directory in the container
  • Step 1: Create a Dockerfile in your Python application directory with the following content:
    FROM dockerfile/python-runtime
  • Step 2: Build your container image by running the following command in your application directory:
    docker build -t="app" .
  • Step 3: Run application by mapping port 8080:
    APP=$(docker run -d -p 8080 app)
    PORT=$(docker port $APP 8080 | awk -F: '{print $2}')
    echo "Open http://localhost:$PORT/"

Tag summary

Content type

Image

Digest

sha256:c43233270…

Size

164.7 MB

Last updated

over 8 years ago

docker pull sxmichael/python-runtime