-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
195 lines (171 loc) · 11.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="en-gb">
<head>
<meta charset="utf-8">
<title>Fig | Fast, isolated development environments using Docker</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Lilita+One|Lato:300,400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/fig.css?20150226081472935746419">
</head>
<body>
<div class="container">
<nav class="deprecation">
<p>Fig has been replaced by Docker Compose, and is now deprecated. The new documentation is on the <a href="https://docs.docker.com/compose/">Docker website</a>.</p>
</nav>
<div class="logo mobile-logo">
<a href="index.html">
<img src="img/logo.png">
Fig
</a>
</div>
<div class="content"><p><strong class="strapline">Fast, isolated development environments using Docker.</strong></p>
<p>Define your app's environment with a <code>Dockerfile</code> so it can be reproduced anywhere:</p>
<div class="highlight"><pre><code class="text language-text" data-lang="text">FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
</code></pre></div>
<p>Define the services that make up your app in <code>fig.yml</code> so they can be run together in an isolated environment:</p>
<div class="highlight"><pre><code class="yaml language-yaml" data-lang="yaml"><span class="l-Scalar-Plain">web</span><span class="p-Indicator">:</span>
<span class="l-Scalar-Plain">build</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">.</span>
<span class="l-Scalar-Plain">command</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">python app.py</span>
<span class="l-Scalar-Plain">links</span><span class="p-Indicator">:</span>
<span class="p-Indicator">-</span> <span class="l-Scalar-Plain">db</span>
<span class="l-Scalar-Plain">ports</span><span class="p-Indicator">:</span>
<span class="p-Indicator">-</span> <span class="s">"8000:8000"</span>
<span class="l-Scalar-Plain">db</span><span class="p-Indicator">:</span>
<span class="l-Scalar-Plain">image</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">postgres</span>
</code></pre></div>
<p>(No more installing Postgres on your laptop!)</p>
<p>Then type <code>fig up</code>, and Fig will start and run your entire app:</p>
<p><img src="https://orchardup.com/static/images/fig-example-large.gif" alt="example fig run"></p>
<p>There are commands to:</p>
<ul>
<li>start, stop and rebuild services</li>
<li>view the status of running services</li>
<li>tail running services' log output</li>
<li>run a one-off command on a service</li>
</ul>
<h2>Quick start</h2>
<p>Let's get a basic Python web app running on Fig. It assumes a little knowledge of Python, but the concepts should be clear if you're not familiar with it.</p>
<p>First, <a href="install.html">install Docker and Fig</a>.</p>
<p>You'll want to make a directory for the project:</p>
<div class="highlight"><pre><code class="text language-text" data-lang="text">$ mkdir figtest
$ cd figtest
</code></pre></div>
<p>Inside this directory, create <code>app.py</code>, a simple web app that uses the Flask framework and increments a value in Redis:</p>
<div class="highlight"><pre><code class="python language-python" data-lang="python"><span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">Flask</span>
<span class="kn">from</span> <span class="nn">redis</span> <span class="kn">import</span> <span class="n">Redis</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>
<span class="n">redis</span> <span class="o">=</span> <span class="n">Redis</span><span class="p">(</span><span class="n">host</span><span class="o">=</span><span class="s">'redis'</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">6379</span><span class="p">)</span>
<span class="nd">@app.route</span><span class="p">(</span><span class="s">'/'</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">hello</span><span class="p">():</span>
<span class="n">redis</span><span class="o">.</span><span class="n">incr</span><span class="p">(</span><span class="s">'hits'</span><span class="p">)</span>
<span class="k">return</span> <span class="s">'Hello World! I have been seen </span><span class="si">%s</span><span class="s"> times.'</span> <span class="o">%</span> <span class="n">redis</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'hits'</span><span class="p">)</span>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span>
<span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">host</span><span class="o">=</span><span class="s">"0.0.0.0"</span><span class="p">,</span> <span class="n">debug</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</code></pre></div>
<p>We define our Python dependencies in a file called <code>requirements.txt</code>:</p>
<div class="highlight"><pre><code class="text language-text" data-lang="text">flask
redis
</code></pre></div>
<p>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 <code>Dockerfile</code>:</p>
<div class="highlight"><pre><code class="text language-text" data-lang="text">FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
</code></pre></div>
<p>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 <a href="https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile">Docker user guide</a> and the <a href="https://docs.docker.com/reference/builder/">Dockerfile reference</a>.</p>
<p>We then define a set of services using <code>fig.yml</code>:</p>
<div class="highlight"><pre><code class="text language-text" data-lang="text">web:
build: .
command: python app.py
ports:
- "5000:5000"
volumes:
- .:/code
links:
- redis
redis:
image: redis
</code></pre></div>
<p>This defines two services:</p>
<ul>
<li><code>web</code>, which is built from <code>Dockerfile</code> in the current directory. It also says to run the command <code>python app.py</code> 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.</li>
<li><code>redis</code>, which uses the public image <a href="https://registry.hub.docker.com/_/redis/">redis</a>. </li>
</ul>
<p>Now if we run <code>fig up</code>, it'll pull a Redis image, build an image for our own code, and start everything up:</p>
<div class="highlight"><pre><code class="text language-text" data-lang="text">$ fig up
Pulling image 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 http://0.0.0.0:5000/
</code></pre></div>
<p>The web app should now be listening on port 5000 on your docker daemon (if you're using boot2docker, <code>boot2docker ip</code> will tell you its address).</p>
<p>If you want to run your services in the background, you can pass the <code>-d</code> flag to <code>fig up</code> and use <code>fig ps</code> to see what is currently running:</p>
<div class="highlight"><pre><code class="text language-text" data-lang="text">$ 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 app.py Up 5000->5000/tcp
</code></pre></div>
<p><code>fig run</code> allows you to run one-off commands for your services. For example, to see what environment variables are available to the <code>web</code> service:</p>
<div class="highlight"><pre><code class="text language-text" data-lang="text">$ fig run web env
</code></pre></div>
<p>See <code>fig --help</code> other commands that are available.</p>
<p>If you started Fig with <code>fig up -d</code>, you'll probably want to stop your services once you've finished with them:</p>
<div class="highlight"><pre><code class="text language-text" data-lang="text">$ fig stop
</code></pre></div>
<p>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, <a href="https://github.com/docker/fig">open an issue on GitHub</a>.</p>
</div>
<div class="sidebar">
<h1 class="logo">
<a href="index.html">
<img src="img/logo.png">
Fig
</a>
</h1>
<ul class="nav">
<li><a href="index.html">Home</a></li>
<li><a href="install.html">Install</a></li>
<li><a href="rails.html">Get started with Rails</a></li>
<li><a href="django.html">Get started with Django</a></li>
<li><a href="wordpress.html">Get started with Wordpress</a></li>
</ul>
<ul class="nav">
<li>Reference:</li>
<ul>
<li><a href="yml.html">fig.yml</a></li>
<li><a href="cli.html">Commands</a></li>
<li><a href="env.html">Environment variables</a></li>
</ul>
</ul>
<ul class="nav">
<li><a href="https://github.com/docker/fig">Fig on GitHub</a></li>
<li><a href="http://webchat.freenode.net/?channels=%23docker-fig&uio=d4">#docker-fig on Freenode</a></li>
</ul>
<p>Fig is a project from <a href="https://www.docker.com">Docker</a>.</p>
<div class="badges">
<iframe src="https://ghbtns.com/github-btn.html?user=docker&repo=fig&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="100" height="20"></iframe>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.fig.sh/">Tweet</a>
</div>
</div>
</div>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-43996733-3', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>