Deploying a Python web app

We’re going to get a simple Python app running on Orchard. We need just two files: a Python file which runs the app, and a Dockerfile which builds an image with its environment.


from flask import Flask
app = Flask(__name__)

def hello():
    return 'Hello World!\n'

if __name__ == "__main__":"", debug=True)

Next, up, Dockerfile:

FROM orchardup/python:2.7
RUN pip install Flask
ADD . /code
CMD python

Here’s what’s happening:

  • We start from a pre-made image with Python 2.7 (FROM).
  • Install Flask via pip (RUN).
  • Add the current directory to the container at /code (ADD).
  • Set /code to be the default working directory for the container (WORKDIR).
  • Set the container’s default command to run the app (CMD).

For more information on how to write Dockerfiles, see the Dockerfile tutorial and the Dockerfile reference.

We can now build the app’s image on Orchard. First, create your default Docker host if it isn’t already running:

$ orchard hosts create
Default host running at

Then build the image with orchard docker build:

$ orchard docker build -t python-example .

This will upload the current directory to the Docker host, run the commands in the Dockerfile and create an image called python-example based on the resulting container.

Once the image has built, we can run it:

$ orchard docker run -d -p 80:5000 python-example

$ orchard docker ps
CONTAINER ID        IMAGE                   COMMAND                CREATED             STATUS              PORTS
62fee4358adb        python-example:latest   /bin/sh -c python ap   6 seconds ago       Up 5 seconds>5000/tcp

The ps command indicates that the app is running. We can now get the IP of our Docker host with orchard hosts:

$ orchard hosts
NAME                SIZE                IP
default             512M      

We can now access the app at that address:

$ curl
Hello World!


Cleaning up

We can stop the container using its ID (or a prefix of it):

$ orchard docker kill 62fee4358adb

Finally, hosts are charged based on how long they’re around for, so if you’re done, you can remove it:

$ orchard hosts rm