Scott Johnston

Getting Started with Docker Orchestration using Fig

Scott Johnston

Last month we announced Docker, Inc.’s acquisition of Orchard, builders of a Docker hosting service as well as an orchestration tool, Fig.  If you’ve started using Docker and have been wondering how to define and control a multi-container service – for example, a web app in one container and a database in another – then we think you’ll find Fig really helpful.

For this first example, we’ll show how to get a Python web app working with Redis, each in a separate container.  We’ll show how Fig lets you define the link between the two containers and indicate that the web app container is dependent on the Redis container.  Finally, we’ll show how, with a single command, Fig will …

  • pull the Redis image from Docker Hub;
  • build the Python app; and
  • start the containers in the correct sequence.

Ready?  Let’s go!

First, install Docker and Fig.

You’ll want to make a directory for the project:

$ mkdir figtest
$ cd figtest

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

from flask import Flask
from redis import Redis
import os
app = Flask(__name__)
redis = Redis(host="redis_1", port=6379)

def hello():
    return 'Hello World! I have been seen %s times.' % redis.get('hits')

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

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


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:

FROM orchardup/python:2.7
ADD . /code
RUN pip install -r requirements.txt

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.

We then define a set of services using fig.yml:

  build: .
  command: python
  - "5000:5000"
  - .:/code
  - redis
  image: orchardup/redis

This defines two services:

  • web, which is built from Dockerfile in the current directory. It also says to run the command python 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.
  • redis, which uses the Docker Hub image orchardup/redis.

Now if we run fig up, it’ll pull a Redis image, build an image for our own code, and start everything up:

$ fig up
Pulling image orchardup/redis...
Building web...
Starting figtest_redis_1...
Starting figtest_web_1...
redis_1 | [8] 02 Jan 18:43:35.576 # Server started, Redis version 2.8.3
web_1   |  * Running on

Open up http://localhost:5000 in your browser (or http://localdocker:5000 if you’re using docker-osx) and you should see it running!

If you want to run your services in the background, you can pass the -d flag to fig up and use fig ps to see what is currently running:

$ fig up -d
Starting figtest_redis_1...
Starting figtest_web_1...
$ fig ps
Name                 Command            State       Ports
figtest_redis_1   /usr/local/bin/run        Up
figtest_web_1     /bin/sh -c python  Up     5000->5000/tcp

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

This obviously just touches the surface of what’s possible with Docker and Fig – check-out the reference links below for more details.  And we’ll be sharing more Docker + Fig orchestration in future posts, so stay tuned.

Dockerize early and often!

Learn More

Continue reading...


20 thoughts on “Getting Started with Docker Orchestration using Fig

  1. Looking good, fig allow to have a simple yaml file to enable people to have an overview of the whole application stack with the needed components.

    Would be nice if the basic docker command would include fig.
    docker-stack up or something like that. Fig is nice but creates confusion for the beginner user.

  2. would this be useful in any way in a production environment? the website only mentions dev environments.

    • Also useful for production!

      • It seems to me that in production, you’d probably want the containers to be supervised in some way (e.g. with system, upstart or supervisord). It would be great to see Fig add some support for this, to allow for consistency from development through to production.

      • Since fig doesn’t handle automatically restarting crashed containers it’s probably a good idea to use something like supervisord/systemd/etc. in production right? If so, what value does fig provide in a production env?

      • Andreas Steffan

        Absolutely! In fact, I skipped over it when I saw it first because of the emphasis on development. It might be missing features for production, but production use should really be mentioned.

  3. Does fig works on Windows + boot2docker? If it does how to install it? (when I try to run downloaded fig, I get command not found error, probably boot2docker is missing some shared library required by fig)

    • I have the same issue did you solve it?

    • If you have Python installed on your computer, you can install fig by invoking the following command in the command prompt:

      %YOUR_PYTHON_PATH%\Scripts\pip install -U fig

      and then, you should be able to use fig in your working directory.

      set BOOT2DOCKER_IP=
      set DOCKER_HOST=tcp://%BOOT2DOCKER_IP%:2375

      %YOUR_PYTHON_PATH%\Scripts\fig up

  4. Manuel Astudillo

    Seems like a little useful tool. Any plans to make fig also work to describe multi-host apps?

  5. Does anyone know of any tool like fig that allows you to specify different configurations? I want to be able to use the same containers, but in slightly different configurations (links/volumes/injected environment variables) for different setups.

    I don’t want a complex orchestration/deployment system right now, just something to declaratively specify these different configurations for local development.

    • You can use the “–file FILE” option to specify an alternate fig configuration file. This way you just need to add e.g. a “fig-production.yml” to your setup and use it with the mentioned option.

  6. I am wondering where this will go compared to Century Link’s Panamax. It seems like they’ve implemented something like fig with a web UI as well. Correct me if I’m wrong. Probably we will just have options, but I am a fan of using tools straight from the docker core team. Just seems more reliable long term.

  7. Hello,

    I am fond of docker of fig but I found linking in fig interfere with model of docker.

    The name of link specified in the fig.yml

    – redis

    do not correspond to the prefix used by corresponding environment variable in the container because the fig manager add the index of the service after the name of the container.

    In your example it is not the environment variable REDIS_PORT… which is injected in container but REDIS_1_PORT…

    For clarity, I would recommend to define distinctly name of the service from the container and simplify name of the container to remove useless prefix added by fig
    build: .
    command: python
    – “5000:5000”
    – .:/code
    – redis_service:redis
    image: orchardup/redis


  8. How do the Fig commands that are the equivalent of the Docker commands (working_dir, entrypoint, user, hostname, domainname, mem_limit, privileged, etc)
    work? Do they replace the equivalent in the Dockerfile? Or should they be used only in one or the other?

    If the Fig.yml commands override the Dockerfile commands, does that imply that a service is not just dockerised, but is now a fig-based dockerised service?

  9. I can see I missed a paragraph at the start of the fig.yml page, which says that the Dockerfile-equivalents are respected in preference to the ones specified in fig.yml.

    But then surely you should ALWAYS use the Dockerfile version of a command if the image may at any point be used without Fig? If you put the commands in fig.yml, but not in the Dockerfile, then the Dockerfile is incomplete and cannot be used on its own.

    And if that is the case, why put the equivalent commands into Fig at all? They are redundant and don’t do anything that Dockerfile versions don’t.

    Based on my current understanding (which may very well be incomplete), this all seems a little muddled.

  10. when run ‘fig up’,the log like this:
    Recreating yttl_cache_1…
    Recreating yttl_db_1…
    Recreating yttl_app_1…
    No such image: d647797b82d5 (tag: latest)
    Problem:I try to fig build my app again,build success,and then I try run fig up to run all containers,then ‘No such image’ out.How to fix this?

Leave a Reply