/azure-functions-docker-python-sample

A sample of using docker to deploy a Python based app

Primary LanguagePythonMIT LicenseMIT

This repository hosts the instructions and neccessary artifacts for building and publishing Python Functions as a Docker container on Linux.

For comprehensive information about Python in Azure Functions, refer to the azure-functions-python-worker repo.

Getting Started

Prerequisites

Download the sample

In a terminal window, run the following command to clone the sample app repository to your local machine, then change to the directory that contains the sample code.

git clone https://github.com/Azure/azure-functions-docker-python-sample.git
cd azure-functions-docker-python-sample

Understanding the environment

In the Git repository, take a look at the Dockerfile. This file describes the environment that is required to run Python functions on Linux.

# Base the image on the built-in Azure Functions Python image
FROM microsoft/azure-functions-python3.6:v2.0.11737-alpha

# Add files from this repo to the root site folder.
COPY . /home/site/wwwroot

# Install requirements
RUN cd /home/site/wwwroot && pip install -r requirements.txt

Build and deploy the custom image

To build and test your image locally, and deploy to Azure, follow the instructions here -

Create a function on Linux using a custom image

Configure storage

Azure Functions needs a storage account in order to run locally.

The best way to add this is to create a Storage Account in Azure and pass the connection string as an environment variable called AzureWebJobsStorage to the docker run command.

docker run -p 8080:80 -it -e AzureWebJobsStorage="{connection-string}" <docker-id>/mydockerimage:v1.0.0

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.