Inside this directory, create app.py, a simple web app that uses the Flask framework and increments a value in Redis:

fromflaskimportFlaskfromredisimportRedisimportosapp=Flask(__name__)redis=Redis(host='redis',port=6379)@app.route('/')defhello():redis.incr('hits')return'Hello World! I have been seen %s times.'%redis.get('hits')if__name__=="__main__":app.run(host="0.0.0.0",debug=True)

We define our Python dependencies in a file called requirements.txt:

flask
redis

Next, we want to create a Docker image containing all of our app's dependencies. We specify how to build one using a file called Dockerfile:

This tells Docker to install Python, our code and our Python dependencies inside a Docker image. For more information on how to write Dockerfiles, see the Docker user guide and the Dockerfile reference.

web, which is built from Dockerfile in the current directory. It also says to run the command python app.py inside the image, forward the exposed port 5000 on the container to port 5000 on the host machine, connect up the Redis service, and mount the current directory inside the container so we can work on code without having to rebuild the image.

fig run allows you to run one-off commands for your services. For example, to see what environment variables are available to the web service:

$ fig run web env

See fig --help other commands that are available.

If you started Fig with fig up -d, you'll probably want to stop your services once you've finished with them:

$ fig stop

That's more-or-less how Fig works. See the reference section below for full details on the commands, configuration file and environment variables. If you have any thoughts or suggestions, open an issue on GitHub.