How to Use a Fig Environment to Develop Locally on OS X

FigEnvironmentOSX

Difficulty: Intermediate

Overview

Docker is an open platform for developers and system administrators to build, ship and run distributed applications.

This tutorial gives pointers and explains how you use a Fig environment to develop code on local computer systems using the Docker platform on OS X.

Boot2Docker, a lightweight Linux distribution made specifically to run Docker containers, internally mounts the code’s home directory from your host machine, and so code volumes work as expected. (For more information on the working, see the Docker 1.3 announcement).

Intended Audience

This tutorial is intended for Developers, Developer Operational personnel and System Administrators.

Scope

The Fig environment can now be used officially with the Docker platform’s OS X installer.
This tutorial guides you on using the Fig environment to develop code on local computer systems using the Docker platform on OS X.

Boot2Docker, a lightweight Linux distribution made specifically to run Docker containers, internally mounts the code’s home directory from your host machine, and so code volumes work as expected. OS X users need not have to resort to trial and error procedures anymore.

How to use fig to develop locally

Architecture Diagram

Describing the System

This section describes the integrated system comprising the Fig environment, Docker platform, Boot2Docker distribution and the procedure to enable the Fig environment to work out-of-the-box with Boot2Docker on OS X.

Key Feature

Boot2Docker: Shared directories on Mac OS X

Definition: Boot2Docker is a lightweight Linux distribution based on Tiny Core Linux made specifically to run Docker containers. It runs completely from RAM, weighs ~27MB and boots in ~5s (YMMV).
Directories can be shared between your Mac and your containers. Using Docker 1.3 and later with the corresponding version of Boot2Docker, host-mounted volumes now work the way you expect them to.

Note: Background: Fig moves all the configuration required to orchestra Docker into a simple clear fig.yml file. It handles all the work of building and running containers, forwarding their ports, sharing volumes, and linking them.

Inventory/Components

  1. Docker: An open platform.
  2. Boot2Docker: A lightweight Linux distribution based on Tiny Core Linux made specifically to run Docker containers. It runs completely from RAM, weighs ~27MB and boots in ~5s (YMMV).
  3. OS X: Graphical interface operating system.

Environment

Fig: A fast, isolated development environment that uses the Docker platform.

Procedure

The following procedure lists the main sequence of steps that enable the Fig environment to work out-of-the-box with Boot2Docker on OS X.  You can consequently use the Fig environment to develop locally.
Note: OS X users need not have to resort to trial and error procedures anymore.

Main Procedure Overview

1.    Run the standard Docker installer.
2.    Download Fig
3.    You are done!

Note:

Tip:

Try to use the same version of Docker and Fig across all teams.

Running the standard Docker installer

Note: Docker is supported on Mac OS X 10.6 “Snow Leopard” or newer.

Background

The Docker Engine uses Linux-specific kernel features. So, you need to use a lightweight virtual machine (VM) to run it on OS X. You use the OS X Docker client to control the virtualized Docker Engine to build, run, and manage Docker containers.
To make this process easier, the Boot2Docker helper application installs a virtual machine (using VirtualBox) that’s all setup to run the Docker daemon.

Running the standard Docker installer involves:
  1. Installing Docker on Mac OS X.
  2. Upgrading Docker if you use an earlier version.
  3. Running Docker.

Refer to the https://docs.docker.com/installation/mac/ page for the complete demonstration, installing, upgrading and running Docker on OS X (that is just summarized in the steps above). This page also provides information on Container port redirection and further details.

Downloading Fig

Fig is a fast, isolated development environment that uses the Docker platform.

Installing Fig involves:
  1. First configuring Docker and Fig using environment variables.
  2. Persisting the environment variables across shell sessions, and
  3. Then installing Fig.

See http://www.fig.sh/install.html for detailed instructions (that are just summarized above) on installing the Fig environment.
Note: Refer to https://github.com/docker/fig/releases/tag/1.0.0 for more Fig commands.

Example

The following command will mount the directory /Users/bob/myapp/src from your Mac into the container:

$ docker run -v /Users/bob/myapp/src:/src [...]

Benefit

This makes it much easier to use Docker for a continuous development flow. You benefit from a predictable containerized development environment, where you don’t have to rebuild a new container every time you change a line in your source code. The benefits are immediately obvious if you are using Fig for your development workflow.

Limitation
boot2docker: Shared directories on Mac OS X

This feature is limited to boot2docker’s virtualbox configuration, cannot be managed dynamically, and only works for directories in /Users.

Example

Related information (applicable to all Operating Systems): More about Fig, Docker and volumes: The Docker commands performed by Fig provides the volumes runtime option. This option allows you to share folders between your host machine and the services’ Docker containers. (Example of a service is Python.) So, any code changes to the contained files are immediately updated on the running container and consequently the local computer.

To stop the running services, you can kill them with Ctrl+C or run fig stop in another terminal window.

Explanation

Behind the scenes, Fig uses Docker to build and then run containers for each service. Running fig up again will restart the previously created containers whose volume changes (files, folders, etc) persist between boots. This means that if you have added data to one of the data stores it will still be present between restarts. You can remove the containers associated with services, and thus any volume changes, by running fig remove [SERVICE].

After a successful build of a service, Fig won’t attempt to rebuild that service on the next up. That means if you want to make any changes to a built service’s Dockerfile, you’ll need to tell Fig to rebuild that image by using fig build [SERVICE].

Fig also gives you the ability to run one-off commands in services using fig run [SERVICE] [COMMAND], e.g. fig run web python.

Conclusion

Docker is an open platform for developers and system administrators to build, ship and run distributed applications.

This tutorial gives pointers and explains how you use the Fig environment to develop code on local computers using Docker. Boot2Docker, a lightweight Linux distribution made specifically to run Docker containers, internally mounts the code’s home directory from your host machine, and so code volumes work as expected.

This further helps Docker enable apps to be quickly assembled from components and eliminates the friction between development, QA, and production environments. As a result, IT can ship faster and run the same app, unchanged, on laptops, data centre Virtual Machines, and any cloud.

If you are a developer, operations personnel or a system administrator and enjoyed this tutorial, you might also like to explore the Related Information underneath in detail to implement this tutorial’s teachings.

Did you find some great strategies of your own? Let us know in the comments section.

Related Information

Additional detailed information regarding the components of this architecture is available at:

  1. http://www.fig.sh/index.html: Complete information on using Fig, the fast, isolated development environment on Docker.
  2. https://docs.docker.com/installation/mac/: Installing Docker on Mac OS X: Version v1.4 (Latest).
  3. http://blog.docker.com/tag/boot2docker/: For information on Fig 1.0: boot2docker compatibility and more.
  4. https://blog.docker.com/2014/10/docker-1-3-signed-images-process-injection-security-options-mac-shared-directories/ for Docker 1.3: Mac shared directories.
  5. http://boot2docker.io/: Consult this page for complete information on boot2docker.
  6. https://github.com/docker/fig/releases/tag/1.0.0: Explore the Release Notes for updates on the Fig environment’s features that will help you work more efficiently!
  7. http://flurdy.com/docs/docker/docker_osx_ubuntu.html: This page explains Docker with OSX and Ubuntu. The Handy Docker > Folder volumes section is relevant to this topic. It discusses sharing the local folders with the Docker container as a volume.
    This directs us to the https://github.com/boot2docker/boot2docker page for a detailed explanation with examples.
    Furthermore, consult this site for troubleshooting in case the command boot2docker up doesn’t work (OSX) and more Boot2Docker related information.

Glossary of Terms

  1. Docker: An open platform for distributed applications for developers and system administrators.
    Build, ship and run the distributed applications:

    1. Build: Develop an app using Docker containers with any language and any toolchain.
    2. Ship: Ship the “Dockerized” app and dependencies anywhere – to QA, teammates, or the cloud – without breaking anything.
    3. Run: Scale to 1000s of nodes, move between data centers and clouds, update with zero downtime and more.
  2. Docker Engine: A portable, lightweight application runtime and packaging tool.
  3. Docker Hub: A cloud service for sharing applications and automating workflows.
  4. Fig: A Docker-based development environment tool.
  5. Boot2Docker: Boot2Docker is a lightweight Linux distribution made specifically to run Docker containers. It runs completely from RAM, is a small ~24MB download and boots in ~5s (YMMV).
  6. OS X: Mac OS X is a series of Unix-based graphical interface operating systems developed and marketed by Apple Inc.

Hello! I am a Technical Publications Project Management professional. In that context - an experienced Technical Author as well with educational background comprising: * A Computer Science degree, various IT certifications * Technical Writing-Publications Project Management ( ~ Vancouver Island University) * Post Graduation ~ Business Administration * Yoga Teacher Education (including a research thesis on how IT professionals should practice Yoga to stay fit) You can reach me at jyotiapply@hotmail.com. I am always eager to discuss endless possibilities that align with my education, career and interests :-). I will be glad to receive your message!

Tagged with: , , ,
Posted in Tutorial
One comment on “How to Use a Fig Environment to Develop Locally on OS X

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories
%d bloggers like this: