mirror of https://github.com/docker/docs.git
2075 lines
94 KiB
XML
2075 lines
94 KiB
XML
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||
<channel>
|
||
<title>Composes on Docker Docs</title>
|
||
<link>http://localhost/compose/</link>
|
||
<description>Recent content in Composes on Docker Docs</description>
|
||
<generator>Hugo -- gohugo.io</generator>
|
||
<language>en-us</language>
|
||
<atom:link href="http://localhost/compose/index.xml" rel="self" type="application/rss+xml" />
|
||
|
||
<item>
|
||
<title></title>
|
||
<link>http://localhost/compose/README/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/README/</guid>
|
||
<description>
|
||
|
||
<h1 id="contributing-to-the-docker-compose-documentation">Contributing to the Docker Compose documentation</h1>
|
||
|
||
<p>The documentation in this directory is part of the <a href="https://docs.docker.com">https://docs.docker.com</a> website. Docker uses <a href="http://gohugo.io/overview/introduction/">the Hugo static generator</a> to convert project Markdown files to a static HTML site.</p>
|
||
|
||
<p>You don&rsquo;t need to be a Hugo expert to contribute to the compose documentation. If you are familiar with Markdown, you can modify the content in the <code>docs</code> files.</p>
|
||
|
||
<p>If you want to add a new file or change the location of the document in the menu, you do need to know a little more.</p>
|
||
|
||
<h2 id="documentation-contributing-workflow">Documentation contributing workflow</h2>
|
||
|
||
<ol>
|
||
<li><p>Edit a Markdown file in the tree.</p></li>
|
||
|
||
<li><p>Save your changes.</p></li>
|
||
|
||
<li><p>Make sure you in your <code>docs</code> subdirectory.</p></li>
|
||
|
||
<li><p>Build the documentation.</p>
|
||
|
||
<pre><code>$ make docs
|
||
---&gt; ffcf3f6c4e97
|
||
Removing intermediate container a676414185e8
|
||
Successfully built ffcf3f6c4e97
|
||
docker run --rm -it -e AWS_S3_BUCKET -e NOCACHE -p 8000:8000 -e DOCKERHOST &quot;docs-base:test-tooling&quot; hugo server --port=8000 --baseUrl=192.168.59.103 --bind=0.0.0.0
|
||
ERROR: 2015/06/13 MenuEntry's .Url is deprecated and will be removed in Hugo 0.15. Use .URL instead.
|
||
0 of 4 drafts rendered
|
||
0 future content
|
||
12 pages created
|
||
0 paginator pages created
|
||
0 tags created
|
||
0 categories created
|
||
in 55 ms
|
||
Serving pages from /docs/public
|
||
Web Server is available at http://0.0.0.0:8000/
|
||
Press Ctrl+C to stop
|
||
</code></pre></li>
|
||
|
||
<li><p>Open the available server in your browser.</p>
|
||
|
||
<p>The documentation server has the complete menu but only the Docker Compose
|
||
documentation resolves. You can&rsquo;t access the other project docs from this
|
||
localized build.</p></li>
|
||
</ol>
|
||
|
||
<h2 id="tips-on-hugo-metadata-and-menu-positioning">Tips on Hugo metadata and menu positioning</h2>
|
||
|
||
<p>The top of each Docker Compose documentation file contains TOML metadata. The metadata is commented out to prevent it from appears in GitHub.</p>
|
||
|
||
<pre><code>&lt;!--[metadata]&gt;
|
||
+++
|
||
title = &quot;Extending services in Compose&quot;
|
||
description = &quot;How to use Docker Compose's extends keyword to share configuration between files and projects&quot;
|
||
keywords = [&quot;fig, composition, compose, docker, orchestration, documentation, docs&quot;]
|
||
[menu.main]
|
||
parent=&quot;smn_workw_compose&quot;
|
||
weight=2
|
||
+++
|
||
&lt;![end-metadata]--&gt;
|
||
</code></pre>
|
||
|
||
<p>The metadata alone has this structure:</p>
|
||
|
||
<pre><code>+++
|
||
title = &quot;Extending services in Compose&quot;
|
||
description = &quot;How to use Docker Compose's extends keyword to share configuration between files and projects&quot;
|
||
keywords = [&quot;fig, composition, compose, docker, orchestration, documentation, docs&quot;]
|
||
[menu.main]
|
||
parent=&quot;smn_workw_compose&quot;
|
||
weight=2
|
||
+++
|
||
</code></pre>
|
||
|
||
<p>The <code>[menu.main]</code> section refers to navigation defined <a href="https://github.com/docker/docs-base/blob/hugo/config.toml">in the main Docker menu</a>. This metadata says <em>add a menu item called</em> Extending services in Compose <em>to the menu with the</em> <code>smn_workdw_compose</code> <em>identifier</em>. If you locate the menu in the configuration, you&rsquo;ll find <em>Create multi-container applications</em> is the menu title.</p>
|
||
|
||
<p>You can move an article in the tree by specifying a new parent. You can shift the location of the item by changing its weight. Higher numbers are heavier and shift the item to the bottom of menu. Low or no numbers shift it up.</p>
|
||
|
||
<h2 id="other-key-documentation-repositories">Other key documentation repositories</h2>
|
||
|
||
<p>The <code>docker/docs-base</code> repository contains <a href="https://github.com/docker/docs-base">the Hugo theme and menu configuration</a>. If you open the <code>Dockerfile</code> you&rsquo;ll see the <code>make docs</code> relies on this as a base image for building the Compose documentation.</p>
|
||
|
||
<p>The <code>docker/docs.docker.com</code> repository contains <a href="https://github.com/docker/docs.docker.com">build system for building the Docker documentation site</a>. Fork this repository to build the entire documentation site.</p>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Command Completion</title>
|
||
<link>http://localhost/compose/completion/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/completion/</guid>
|
||
<description>
|
||
|
||
<h1 id="command-completion">Command Completion</h1>
|
||
|
||
<p>Compose comes with <a href="http://en.wikipedia.org/wiki/Command-line_completion">command completion</a>
|
||
for the bash and zsh shell.</p>
|
||
|
||
<h2 id="installing-command-completion">Installing Command Completion</h2>
|
||
|
||
<h3 id="bash">Bash</h3>
|
||
|
||
<p>Make sure bash completion is installed. If you use a current Linux in a non-minimal installation, bash completion should be available.
|
||
On a Mac, install with <code>brew install bash-completion</code></p>
|
||
|
||
<p>Place the completion script in <code>/etc/bash_completion.d/</code> (<code>/usr/local/etc/bash_completion.d/</code> on a Mac), using e.g.</p>
|
||
|
||
<pre><code> curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose --version | awk 'NR==1{print $NF}')/contrib/completion/bash/docker-compose &gt; /etc/bash_completion.d/docker-compose
|
||
</code></pre>
|
||
|
||
<p>Completion will be available upon next login.</p>
|
||
|
||
<h3 id="zsh">Zsh</h3>
|
||
|
||
<p>Place the completion script in your <code>/path/to/zsh/completion</code>, using e.g. <code>~/.zsh/completion/</code></p>
|
||
|
||
<pre><code>mkdir -p ~/.zsh/completion
|
||
curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose --version | awk 'NR==1{print $NF}')/contrib/completion/zsh/_docker-compose &gt; ~/.zsh/completion/_docker-compose
|
||
</code></pre>
|
||
|
||
<p>Include the directory in your <code>$fpath</code>, e.g. by adding in <code>~/.zshrc</code></p>
|
||
|
||
<pre><code>fpath=(~/.zsh/completion $fpath)
|
||
</code></pre>
|
||
|
||
<p>Make sure <code>compinit</code> is loaded or do it by adding in <code>~/.zshrc</code></p>
|
||
|
||
<pre><code>autoload -Uz compinit &amp;&amp; compinit -i
|
||
</code></pre>
|
||
|
||
<p>Then reload your shell</p>
|
||
|
||
<pre><code>exec $SHELL -l
|
||
</code></pre>
|
||
|
||
<h2 id="available-completions">Available completions</h2>
|
||
|
||
<p>Depending on what you typed on the command line so far, it will complete</p>
|
||
|
||
<ul>
|
||
<li>available docker-compose commands</li>
|
||
<li>options that are available for a particular command</li>
|
||
<li>service names that make sense in a given context (e.g. services with running or stopped instances or services based on images vs. services based on Dockerfiles). For <code>docker-compose scale</code>, completed service names will automatically have &ldquo;=&rdquo; appended.</li>
|
||
<li>arguments for selected options, e.g. <code>docker-compose kill -s</code> will complete some signals like SIGHUP and SIGUSR1.</li>
|
||
</ul>
|
||
|
||
<p>Enjoy working with Compose faster and with less typos!</p>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/">User guide</a></li>
|
||
<li><a href="http://localhost/compose/install">Installing Compose</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/cli">Command line reference</a></li>
|
||
<li><a href="http://localhost/compose/yml">Yaml file reference</a></li>
|
||
<li><a href="http://localhost/compose/env">Compose environment variables</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Compose CLI reference</title>
|
||
<link>http://localhost/compose/cli/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/cli/</guid>
|
||
<description>
|
||
|
||
<h1 id="compose-cli-reference">Compose CLI reference</h1>
|
||
|
||
<p>Most Docker Compose commands are run against one or more services. If
|
||
the service is not specified, the command will apply to all services.</p>
|
||
|
||
<p>For full usage information, run <code>docker-compose [COMMAND] --help</code>.</p>
|
||
|
||
<h2 id="commands">Commands</h2>
|
||
|
||
<h3 id="build">build</h3>
|
||
|
||
<p>Builds or rebuilds services.</p>
|
||
|
||
<p>Services are built once and then tagged as <code>project_service</code>, e.g.,
|
||
<code>composetest_db</code>. If you change a service&rsquo;s Dockerfile or the contents of its
|
||
build directory, run <code>docker-compose build</code> to rebuild it.</p>
|
||
|
||
<h3 id="help">help</h3>
|
||
|
||
<p>Displays help and usage instructions for a command.</p>
|
||
|
||
<h3 id="kill">kill</h3>
|
||
|
||
<p>Forces running containers to stop by sending a <code>SIGKILL</code> signal. Optionally the
|
||
signal can be passed, for example:</p>
|
||
|
||
<pre><code>$ docker-compose kill -s SIGINT
|
||
</code></pre>
|
||
|
||
<h3 id="logs">logs</h3>
|
||
|
||
<p>Displays log output from services.</p>
|
||
|
||
<h3 id="port">port</h3>
|
||
|
||
<p>Prints the public port for a port binding</p>
|
||
|
||
<h3 id="ps">ps</h3>
|
||
|
||
<p>Lists containers.</p>
|
||
|
||
<h3 id="pull">pull</h3>
|
||
|
||
<p>Pulls service images.</p>
|
||
|
||
<h3 id="restart">restart</h3>
|
||
|
||
<p>Restarts services.</p>
|
||
|
||
<h3 id="rm">rm</h3>
|
||
|
||
<p>Removes stopped service containers.</p>
|
||
|
||
<h3 id="run">run</h3>
|
||
|
||
<p>Runs a one-off command on a service.</p>
|
||
|
||
<p>For example,</p>
|
||
|
||
<pre><code>$ docker-compose run web python manage.py shell
|
||
</code></pre>
|
||
|
||
<p>will start the <code>web</code> service and then run <code>manage.py shell</code> in python.
|
||
Note that by default, linked services will also be started, unless they are
|
||
already running.</p>
|
||
|
||
<p>One-off commands are started in new containers with the same configuration as a
|
||
normal container for that service, so volumes, links, etc will all be created as
|
||
expected. When using <code>run</code>, there are two differences from bringing up a
|
||
container normally:</p>
|
||
|
||
<ol>
|
||
<li><p>the command will be overridden with the one specified. So, if you run
|
||
<code>docker-compose run web bash</code>, the container&rsquo;s web command (which could default
|
||
to, e.g., <code>python app.py</code>) will be overridden to <code>bash</code></p></li>
|
||
|
||
<li><p>by default no ports will be created in case they collide with already opened
|
||
ports.</p></li>
|
||
</ol>
|
||
|
||
<p>Links are also created between one-off commands and the other containers which
|
||
are part of that service. So, for example, you could run:</p>
|
||
|
||
<pre><code>$ docker-compose run db psql -h db -U docker
|
||
</code></pre>
|
||
|
||
<p>This would open up an interactive PostgreSQL shell for the linked <code>db</code> container
|
||
(which would get created or started as needed).</p>
|
||
|
||
<p>If you do not want linked containers to start when running the one-off command,
|
||
specify the <code>--no-deps</code> flag:</p>
|
||
|
||
<pre><code>$ docker-compose run --no-deps web python manage.py shell
|
||
</code></pre>
|
||
|
||
<p>Similarly, if you do want the service&rsquo;s ports to be created and mapped to the
|
||
host, specify the <code>--service-ports</code> flag:</p>
|
||
|
||
<pre><code>$ docker-compose run --service-ports web python manage.py shell
|
||
</code></pre>
|
||
|
||
<h3 id="scale">scale</h3>
|
||
|
||
<p>Sets the number of containers to run for a service.</p>
|
||
|
||
<p>Numbers are specified as arguments in the form <code>service=num</code>. For example:</p>
|
||
|
||
<pre><code>$ docker-compose scale web=2 worker=3
|
||
</code></pre>
|
||
|
||
<h3 id="start">start</h3>
|
||
|
||
<p>Starts existing containers for a service.</p>
|
||
|
||
<h3 id="stop">stop</h3>
|
||
|
||
<p>Stops running containers without removing them. They can be started again with
|
||
<code>docker-compose start</code>.</p>
|
||
|
||
<h3 id="up">up</h3>
|
||
|
||
<p>Builds, (re)creates, starts, and attaches to containers for a service.</p>
|
||
|
||
<p>Linked services will be started, unless they are already running.</p>
|
||
|
||
<p>By default, <code>docker-compose up</code> will aggregate the output of each container and,
|
||
when it exits, all containers will be stopped. Running <code>docker-compose up -d</code>,
|
||
will start the containers in the background and leave them running.</p>
|
||
|
||
<p>By default, if there are existing containers for a service, <code>docker-compose up</code> will stop and recreate them (preserving mounted volumes with <a href="http://docs.docker.io/en/latest/use/working_with_volumes/">volumes-from</a>), so that changes in <code>docker-compose.yml</code> are picked up. If you do not want containers stopped and recreated, use <code>docker-compose up --no-recreate</code>. This will still start any stopped containers, if needed.</p>
|
||
|
||
<h2 id="options">Options</h2>
|
||
|
||
<h3 id="verbose">&ndash;verbose</h3>
|
||
|
||
<p>Shows more output</p>
|
||
|
||
<h3 id="v-version">-v, &ndash;version</h3>
|
||
|
||
<p>Prints version and exits</p>
|
||
|
||
<h3 id="f-file-file">-f, &ndash;file FILE</h3>
|
||
|
||
<p>Specify what file to read configuration from. If not provided, Compose will look
|
||
for <code>docker-compose.yml</code> in the current working directory, and then each parent
|
||
directory successively, until found.</p>
|
||
|
||
<h3 id="p-project-name-name">-p, &ndash;project-name NAME</h3>
|
||
|
||
<p>Specifies an alternate project name (default: current directory name)</p>
|
||
|
||
<h2 id="environment-variables">Environment Variables</h2>
|
||
|
||
<p>Several environment variables are available for you to configure Compose&rsquo;s behaviour.</p>
|
||
|
||
<p>Variables starting with <code>DOCKER_</code> are the same as those used to configure the
|
||
Docker command-line client. If you&rsquo;re using boot2docker, <code>eval &quot;$(boot2docker shellinit)&quot;</code>
|
||
will set them to their correct values.</p>
|
||
|
||
<h3 id="compose-project-name">COMPOSE_PROJECT_NAME</h3>
|
||
|
||
<p>Sets the project name, which is prepended to the name of every container started by Compose. Defaults to the <code>basename</code> of the current working directory.</p>
|
||
|
||
<h3 id="compose-file">COMPOSE_FILE</h3>
|
||
|
||
<p>Specify what file to read configuration from. If not provided, Compose will look
|
||
for <code>docker-compose.yml</code> in the current working directory, and then each parent
|
||
directory successively, until found.</p>
|
||
|
||
<h3 id="docker-host">DOCKER_HOST</h3>
|
||
|
||
<p>Sets the URL of the docker daemon. As with the Docker client, defaults to <code>unix:///var/run/docker.sock</code>.</p>
|
||
|
||
<h3 id="docker-tls-verify">DOCKER_TLS_VERIFY</h3>
|
||
|
||
<p>When set to anything other than an empty string, enables TLS communication with
|
||
the daemon.</p>
|
||
|
||
<h3 id="docker-cert-path">DOCKER_CERT_PATH</h3>
|
||
|
||
<p>Configures the path to the <code>ca.pem</code>, <code>cert.pem</code>, and <code>key.pem</code> files used for TLS verification. Defaults to <code>~/.docker</code>.</p>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/">User guide</a></li>
|
||
<li><a href="http://localhost/compose/install">Installing Compose</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/yml">Yaml file reference</a></li>
|
||
<li><a href="http://localhost/compose/env">Compose environment variables</a></li>
|
||
<li><a href="http://localhost/compose/completion">Compose command line completion</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Compose environment variables reference</title>
|
||
<link>http://localhost/compose/env/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/env/</guid>
|
||
<description>
|
||
|
||
<h1 id="compose-environment-variables-reference">Compose environment variables reference</h1>
|
||
|
||
<p>===============================</p>
|
||
|
||
<p><strong>Note:</strong> Environment variables are no longer the recommended method for connecting to linked services. Instead, you should use the link name (by default, the name of the linked service) as the hostname to connect to. See the <a href="http://localhost/compose/yml#links">docker-compose.yml documentation</a> for details.</p>
|
||
|
||
<p>Compose uses <a href="http://docs.docker.com/userguide/dockerlinks/">Docker links</a> to expose services&rsquo; containers to one another. Each linked container injects a set of environment variables, each of which begins with the uppercase name of the container.</p>
|
||
|
||
<p>To see what environment variables are available to a service, run <code>docker-compose run SERVICE env</code>.</p>
|
||
|
||
<p><b><i>name</i>_PORT</b><br>
|
||
Full URL, e.g. <code>DB_PORT=tcp://172.17.0.5:5432</code></p>
|
||
|
||
<p><b><i>name</i>_PORT_<i>num</i>_<i>protocol</i></b><br>
|
||
Full URL, e.g. <code>DB_PORT_5432_TCP=tcp://172.17.0.5:5432</code></p>
|
||
|
||
<p><b><i>name</i>_PORT_<i>num</i>_<i>protocol</i>_ADDR</b><br>
|
||
Container&rsquo;s IP address, e.g. <code>DB_PORT_5432_TCP_ADDR=172.17.0.5</code></p>
|
||
|
||
<p><b><i>name</i>_PORT_<i>num</i>_<i>protocol</i>_PORT</b><br>
|
||
Exposed port number, e.g. <code>DB_PORT_5432_TCP_PORT=5432</code></p>
|
||
|
||
<p><b><i>name</i>_PORT_<i>num</i>_<i>protocol</i>_PROTO</b><br>
|
||
Protocol (tcp or udp), e.g. <code>DB_PORT_5432_TCP_PROTO=tcp</code></p>
|
||
|
||
<p><b><i>name</i>_NAME</b><br>
|
||
Fully qualified container name, e.g. <code>DB_1_NAME=/myapp_web_1/myapp_db_1</code></p>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/">User guide</a></li>
|
||
<li><a href="http://localhost/compose/install">Installing Compose</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/cli">Command line reference</a></li>
|
||
<li><a href="http://localhost/compose/yml">Yaml file reference</a></li>
|
||
<li><a href="http://localhost/compose/completion">Compose command line completion</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Docker Compose</title>
|
||
<link>http://localhost/compose/install/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/install/</guid>
|
||
<description>
|
||
|
||
<h1 id="install-docker-compose">Install Docker Compose</h1>
|
||
|
||
<p>To install Compose, you&rsquo;ll need to install Docker first. You&rsquo;ll then install
|
||
Compose with a <code>curl</code> command.</p>
|
||
|
||
<h2 id="install-docker">Install Docker</h2>
|
||
|
||
<p>First, install Docker version 1.6 or greater:</p>
|
||
|
||
<ul>
|
||
<li><a href="http://docs.docker.com/installation/mac/">Instructions for Mac OS X</a></li>
|
||
<li><a href="http://docs.docker.com/installation/ubuntulinux/">Instructions for Ubuntu</a></li>
|
||
<li><a href="http://docs.docker.com/installation/">Instructions for other systems</a></li>
|
||
</ul>
|
||
|
||
<h2 id="install-compose">Install Compose</h2>
|
||
|
||
<p>To install Compose, run the following commands:</p>
|
||
|
||
<pre><code>curl -L https://github.com/docker/compose/releases/download/1.3.1/docker-compose-`uname -s`-`uname -m` &gt; /usr/local/bin/docker-compose
|
||
chmod +x /usr/local/bin/docker-compose
|
||
</code></pre>
|
||
|
||
<blockquote>
|
||
<p>Note: If you get a &ldquo;Permission denied&rdquo; error, your <code>/usr/local/bin</code> directory probably isn&rsquo;t writable and you&rsquo;ll need to install Compose as the superuser. Run <code>sudo -i</code>, then the two commands above, then <code>exit</code>.</p>
|
||
</blockquote>
|
||
|
||
<p>Optionally, you can also install <a href="http://localhost/compose/completion">command completion</a> for the
|
||
bash shell.</p>
|
||
|
||
<p>Compose is available for OS X and 64-bit Linux. If you&rsquo;re on another platform,
|
||
Compose can also be installed as a Python package:</p>
|
||
|
||
<pre><code>$ sudo pip install -U docker-compose
|
||
</code></pre>
|
||
|
||
<p>No further steps are required; Compose should now be successfully installed.
|
||
You can test the installation by running <code>docker-compose --version</code>.</p>
|
||
|
||
<h3 id="upgrading">Upgrading</h3>
|
||
|
||
<p>If you&rsquo;re coming from Compose 1.2 or earlier, you&rsquo;ll need to remove or migrate your existing containers after upgrading Compose. This is because, as of version 1.3, Compose uses Docker labels to keep track of containers, and so they need to be recreated with labels added.</p>
|
||
|
||
<p>If Compose detects containers that were created without labels, it will refuse to run so that you don&rsquo;t end up with two sets of them. If you want to keep using your existing containers (for example, because they have data volumes you want to preserve) you can migrate them with the following command:</p>
|
||
|
||
<pre><code>docker-compose migrate-to-labels
|
||
</code></pre>
|
||
|
||
<p>Alternatively, if you&rsquo;re not worried about keeping them, you can remove them - Compose will just create new ones.</p>
|
||
|
||
<pre><code>docker rm -f myapp_web_1 myapp_db_1 ...
|
||
</code></pre>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/">User guide</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/cli">Command line reference</a></li>
|
||
<li><a href="http://localhost/compose/yml">Yaml file reference</a></li>
|
||
<li><a href="http://localhost/compose/env">Compose environment variables</a></li>
|
||
<li><a href="http://localhost/compose/completion">Compose command line completion</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Extending services in Compose</title>
|
||
<link>http://localhost/compose/extends/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/extends/</guid>
|
||
<description>
|
||
|
||
<h2 id="extending-services-in-compose">Extending services in Compose</h2>
|
||
|
||
<p>Docker Compose&rsquo;s <code>extends</code> keyword enables sharing of common configurations
|
||
among different files, or even different projects entirely. Extending services
|
||
is useful if you have several applications that reuse commonly-defined services.
|
||
Using <code>extends</code> you can define a service in one place and refer to it from
|
||
anywhere.</p>
|
||
|
||
<p>Alternatively, you can deploy the same application to multiple environments with
|
||
a slightly different set of services in each case (or with changes to the
|
||
configuration of some services). Moreover, you can do so without copy-pasting
|
||
the configuration around.</p>
|
||
|
||
<h3 id="understand-the-extends-configuration">Understand the extends configuration</h3>
|
||
|
||
<p>When defining any service in <code>docker-compose.yml</code>, you can declare that you are
|
||
extending another service like this:</p>
|
||
|
||
<pre><code>web:
|
||
extends:
|
||
file: common-services.yml
|
||
service: webapp
|
||
</code></pre>
|
||
|
||
<p>This instructs Compose to re-use the configuration for the <code>webapp</code> service
|
||
defined in the <code>common-services.yml</code> file. Suppose that <code>common-services.yml</code>
|
||
looks like this:</p>
|
||
|
||
<pre><code>webapp:
|
||
build: .
|
||
ports:
|
||
- &quot;8000:8000&quot;
|
||
volumes:
|
||
- &quot;/data&quot;
|
||
</code></pre>
|
||
|
||
<p>In this case, you&rsquo;ll get exactly the same result as if you wrote
|
||
<code>docker-compose.yml</code> with that <code>build</code>, <code>ports</code> and <code>volumes</code> configuration
|
||
defined directly under <code>web</code>.</p>
|
||
|
||
<p>You can go further and define (or re-define) configuration locally in
|
||
<code>docker-compose.yml</code>:</p>
|
||
|
||
<pre><code>web:
|
||
extends:
|
||
file: common-services.yml
|
||
service: webapp
|
||
environment:
|
||
- DEBUG=1
|
||
cpu_shares: 5
|
||
</code></pre>
|
||
|
||
<p>You can also write other services and link your <code>web</code> service to them:</p>
|
||
|
||
<pre><code>web:
|
||
extends:
|
||
file: common-services.yml
|
||
service: webapp
|
||
environment:
|
||
- DEBUG=1
|
||
cpu_shares: 5
|
||
links:
|
||
- db
|
||
db:
|
||
image: postgres
|
||
</code></pre>
|
||
|
||
<p>For full details on how to use <code>extends</code>, refer to the <a href="#reference">reference</a>.</p>
|
||
|
||
<h3 id="example-use-case">Example use case</h3>
|
||
|
||
<p>In this example, you’ll repurpose the example app from the <a href="http://localhost/compose/index">quick start
|
||
guide</a>. (If you&rsquo;re not familiar with Compose, it&rsquo;s recommended that
|
||
you go through the quick start first.) This example assumes you want to use
|
||
Compose both to develop an application locally and then deploy it to a
|
||
production environment.</p>
|
||
|
||
<p>The local and production environments are similar, but there are some
|
||
differences. In development, you mount the application code as a volume so that
|
||
it can pick up changes; in production, the code should be immutable from the
|
||
outside. This ensures it’s not accidentally changed. The development environment
|
||
uses a local Redis container, but in production another team manages the Redis
|
||
service, which is listening at <code>redis-production.example.com</code>.</p>
|
||
|
||
<p>To configure with <code>extends</code> for this sample, you must:</p>
|
||
|
||
<ol>
|
||
<li><p>Define the web application as a Docker image in <code>Dockerfile</code> and a Compose
|
||
service in <code>common.yml</code>.</p></li>
|
||
|
||
<li><p>Define the development environment in the standard Compose file,
|
||
<code>docker-compose.yml</code>.</p>
|
||
|
||
<ul>
|
||
<li>Use <code>extends</code> to pull in the web service.</li>
|
||
<li>Configure a volume to enable code reloading.</li>
|
||
<li>Create an additional Redis service for the application to use locally.</li>
|
||
</ul></li>
|
||
|
||
<li><p>Define the production environment in a third Compose file, <code>production.yml</code>.</p>
|
||
|
||
<ul>
|
||
<li>Use <code>extends</code> to pull in the web service.</li>
|
||
<li>Configure the web service to talk to the external, production Redis service.</li>
|
||
</ul></li>
|
||
</ol>
|
||
|
||
<h4 id="define-the-web-app">Define the web app</h4>
|
||
|
||
<p>Defining the web application requires the following:</p>
|
||
|
||
<ol>
|
||
<li><p>Create an <code>app.py</code> file.</p>
|
||
|
||
<p>This file contains a simple Python application that uses Flask to serve HTTP
|
||
and increments a counter in Redis:</p>
|
||
|
||
<pre><code>from flask import Flask
|
||
from redis import Redis
|
||
import os
|
||
|
||
|
||
app = Flask(__name__)
|
||
redis = Redis(host=os.environ['REDIS_HOST'], port=6379)
|
||
|
||
|
||
@app.route('/')
|
||
def hello():
|
||
redis.incr('hits')
|
||
return 'Hello World! I have been seen %s times.\n' % redis.get('hits')
|
||
|
||
|
||
if __name__ == &quot;__main__&quot;:
|
||
app.run(host=&quot;0.0.0.0&quot;, debug=True)
|
||
</code></pre>
|
||
|
||
<p>This code uses a <code>REDIS_HOST</code> environment variable to determine where to
|
||
find Redis.</p></li>
|
||
|
||
<li><p>Define the Python dependencies in a <code>requirements.txt</code> file:</p>
|
||
|
||
<pre><code>flask
|
||
redis
|
||
</code></pre></li>
|
||
|
||
<li><p>Create a <code>Dockerfile</code> to build an image containing the app:</p>
|
||
|
||
<pre><code>FROM python:2.7
|
||
ADD . /code
|
||
WORKDIR /code
|
||
RUN pip install -r requirements.txt
|
||
CMD python app.py
|
||
</code></pre></li>
|
||
|
||
<li><p>Create a Compose configuration file called <code>common.yml</code>:</p>
|
||
|
||
<p>This configuration defines how to run the app.</p>
|
||
|
||
<pre><code>web:
|
||
build: .
|
||
ports:
|
||
- &quot;5000:5000&quot;
|
||
</code></pre>
|
||
|
||
<p>Typically, you would have dropped this configuration into
|
||
<code>docker-compose.yml</code> file, but in order to pull it into multiple files with
|
||
<code>extends</code>, it needs to be in a separate file.</p></li>
|
||
</ol>
|
||
|
||
<h4 id="define-the-development-environment">Define the development environment</h4>
|
||
|
||
<ol>
|
||
<li><p>Create a <code>docker-compose.yml</code> file.</p>
|
||
|
||
<p>The <code>extends</code> option pulls in the <code>web</code> service from the <code>common.yml</code> file
|
||
you created in the previous section.</p>
|
||
|
||
<pre><code>web:
|
||
extends:
|
||
file: common.yml
|
||
service: web
|
||
volumes:
|
||
- .:/code
|
||
links:
|
||
- redis
|
||
environment:
|
||
- REDIS_HOST=redis
|
||
redis:
|
||
image: redis
|
||
</code></pre>
|
||
|
||
<p>The new addition defines a <code>web</code> service that:</p>
|
||
|
||
<ul>
|
||
<li>Fetches the base configuration for <code>web</code> out of <code>common.yml</code>.</li>
|
||
<li>Adds <code>volumes</code> and <code>links</code> configuration to the base (<code>common.yml</code>)
|
||
configuration.</li>
|
||
<li>Sets the <code>REDIS_HOST</code> environment variable to point to the linked redis
|
||
container. This environment uses a stock <code>redis</code> image from the Docker Hub.</li>
|
||
</ul></li>
|
||
|
||
<li><p>Run <code>docker-compose up</code>.</p>
|
||
|
||
<p>Compose creates, links, and starts a web and redis container linked together.
|
||
It mounts your application code inside the web container.</p></li>
|
||
|
||
<li><p>Verify that the code is mounted by changing the message in
|
||
<code>app.py</code>&mdash;say, from <code>Hello world!</code> to <code>Hello from Compose!</code>.</p>
|
||
|
||
<p>Don&rsquo;t forget to refresh your browser to see the change!</p></li>
|
||
</ol>
|
||
|
||
<h4 id="define-the-production-environment">Define the production environment</h4>
|
||
|
||
<p>You are almost done. Now, define your production environment:</p>
|
||
|
||
<ol>
|
||
<li><p>Create a <code>production.yml</code> file.</p>
|
||
|
||
<p>As with <code>docker-compose.yml</code>, the <code>extends</code> option pulls in the <code>web</code> service
|
||
from <code>common.yml</code>.</p>
|
||
|
||
<pre><code>web:
|
||
extends:
|
||
file: common.yml
|
||
service: web
|
||
environment:
|
||
- REDIS_HOST=redis-production.example.com
|
||
</code></pre></li>
|
||
|
||
<li><p>Run <code>docker-compose -f production.yml up</code>.</p>
|
||
|
||
<p>Compose creates <em>just</em> a web container and configures the Redis connection via
|
||
the <code>REDIS_HOST</code> environment variable. This variable points to the production
|
||
Redis instance.</p>
|
||
|
||
<blockquote>
|
||
<p><strong>Note</strong>: If you try to load up the webapp in your browser you&rsquo;ll get an
|
||
error&mdash;<code>redis-production.example.com</code> isn&rsquo;t actually a Redis server.</p>
|
||
</blockquote></li>
|
||
</ol>
|
||
|
||
<p>You&rsquo;ve now done a basic <code>extends</code> configuration. As your application develops,
|
||
you can make any necessary changes to the web service in <code>common.yml</code>. Compose
|
||
picks up both the development and production environments when you next run
|
||
<code>docker-compose</code>. You don&rsquo;t have to do any copy-and-paste, and you don&rsquo;t have to
|
||
manually keep both environments in sync.</p>
|
||
|
||
<h3 id="reference">Reference</h3>
|
||
|
||
<p>You can use <code>extends</code> on any service together with other configuration keys. It
|
||
always expects a dictionary that should always contain two keys: <code>file</code> and
|
||
<code>service</code>.</p>
|
||
|
||
<p>The <code>file</code> key specifies which file to look in. It can be an absolute path or a
|
||
relative one&mdash;if relative, it&rsquo;s treated as relative to the current file.</p>
|
||
|
||
<p>The <code>service</code> key specifies the name of the service to extend, for example <code>web</code>
|
||
or <code>database</code>.</p>
|
||
|
||
<p>You can extend a service that itself extends another. You can extend
|
||
indefinitely. Compose does not support circular references and <code>docker-compose</code>
|
||
returns an error if it encounters them.</p>
|
||
|
||
<h4 id="adding-and-overriding-configuration">Adding and overriding configuration</h4>
|
||
|
||
<p>Compose copies configurations from the original service over to the local one,
|
||
<strong>except</strong> for <code>links</code> and <code>volumes_from</code>. These exceptions exist to avoid
|
||
implicit dependencies&mdash;you always define <code>links</code> and <code>volumes_from</code>
|
||
locally. This ensures dependencies between services are clearly visible when
|
||
reading the current file. Defining these locally also ensures changes to the
|
||
referenced file don&rsquo;t result in breakage.</p>
|
||
|
||
<p>If a configuration option is defined in both the original service and the local
|
||
service, the local value either *override*s or *extend*s the definition of the
|
||
original service. This works differently for other configuration options.</p>
|
||
|
||
<p>For single-value options like <code>image</code>, <code>command</code> or <code>mem_limit</code>, the new value
|
||
replaces the old value. <strong>This is the default behaviour - all exceptions are
|
||
listed below.</strong></p>
|
||
|
||
<pre><code># original service
|
||
command: python app.py
|
||
|
||
# local service
|
||
command: python otherapp.py
|
||
|
||
# result
|
||
command: python otherapp.py
|
||
</code></pre>
|
||
|
||
<p>In the case of <code>build</code> and <code>image</code>, using one in the local service causes
|
||
Compose to discard the other, if it was defined in the original service.</p>
|
||
|
||
<pre><code># original service
|
||
build: .
|
||
|
||
# local service
|
||
image: redis
|
||
|
||
# result
|
||
image: redis
|
||
|
||
# original service
|
||
image: redis
|
||
|
||
# local service
|
||
build: .
|
||
|
||
# result
|
||
build: .
|
||
</code></pre>
|
||
|
||
<p>For the <strong>multi-value options</strong> <code>ports</code>, <code>expose</code>, <code>external_links</code>, <code>dns</code> and
|
||
<code>dns_search</code>, Compose concatenates both sets of values:</p>
|
||
|
||
<pre><code># original service
|
||
expose:
|
||
- &quot;3000&quot;
|
||
|
||
# local service
|
||
expose:
|
||
- &quot;4000&quot;
|
||
- &quot;5000&quot;
|
||
|
||
# result
|
||
expose:
|
||
- &quot;3000&quot;
|
||
- &quot;4000&quot;
|
||
- &quot;5000&quot;
|
||
</code></pre>
|
||
|
||
<p>In the case of <code>environment</code> and <code>labels</code>, Compose &ldquo;merges&rdquo; entries together
|
||
with locally-defined values taking precedence:</p>
|
||
|
||
<pre><code># original service
|
||
environment:
|
||
- FOO=original
|
||
- BAR=original
|
||
|
||
# local service
|
||
environment:
|
||
- BAR=local
|
||
- BAZ=local
|
||
|
||
# result
|
||
environment:
|
||
- FOO=original
|
||
- BAR=local
|
||
- BAZ=local
|
||
</code></pre>
|
||
|
||
<p>Finally, for <code>volumes</code> and <code>devices</code>, Compose &ldquo;merges&rdquo; entries together with
|
||
locally-defined bindings taking precedence:</p>
|
||
|
||
<pre><code># original service
|
||
volumes:
|
||
- /original-dir/foo:/foo
|
||
- /original-dir/bar:/bar
|
||
|
||
# local service
|
||
volumes:
|
||
- /local-dir/bar:/bar
|
||
- /local-dir/baz/:baz
|
||
|
||
# result
|
||
volumes:
|
||
- /original-dir/foo:/foo
|
||
- /local-dir/bar:/bar
|
||
- /local-dir/baz/:baz
|
||
</code></pre>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/">User guide</a></li>
|
||
<li><a href="http://localhost/compose/install">Installing Compose</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/cli">Command line reference</a></li>
|
||
<li><a href="http://localhost/compose/yml">Yaml file reference</a></li>
|
||
<li><a href="http://localhost/compose/completion">Compose command line completion</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Overview of Docker Compose</title>
|
||
<link>http://localhost/compose/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/</guid>
|
||
<description>
|
||
|
||
<h1 id="overview-of-docker-compose">Overview of Docker Compose</h1>
|
||
|
||
<p>Compose is a tool for defining and running multi-container applications with
|
||
Docker. With Compose, you define a multi-container application in a single
|
||
file, then spin your application up in a single command which does everything
|
||
that needs to be done to get it running.</p>
|
||
|
||
<p>Compose is great for development environments, staging servers, and CI. We don&rsquo;t
|
||
recommend that you use it in production yet.</p>
|
||
|
||
<p>Using Compose is basically a three-step process.</p>
|
||
|
||
<ol>
|
||
<li>Define your app&rsquo;s environment with a <code>Dockerfile</code> so it can be
|
||
reproduced anywhere.</li>
|
||
<li>Define the services that make up your app in <code>docker-compose.yml</code> so
|
||
they can be run together in an isolated environment:</li>
|
||
<li>Lastly, run <code>docker-compose up</code> and Compose will start and run your entire app.</li>
|
||
</ol>
|
||
|
||
<p>A <code>docker-compose.yml</code> looks like this:</p>
|
||
|
||
<pre><code>web:
|
||
build: .
|
||
ports:
|
||
- &quot;5000:5000&quot;
|
||
volumes:
|
||
- .:/code
|
||
links:
|
||
- redis
|
||
redis:
|
||
image: redis
|
||
</code></pre>
|
||
|
||
<p>Compose has commands for managing the whole lifecycle of your application:</p>
|
||
|
||
<ul>
|
||
<li>Start, stop and rebuild services</li>
|
||
<li>View the status of running services</li>
|
||
<li>Stream the log output of running services</li>
|
||
<li>Run a one-off command on a service</li>
|
||
</ul>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/install">Installing Compose</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/cli">Command line reference</a></li>
|
||
<li><a href="http://localhost/compose/yml">Yaml file reference</a></li>
|
||
<li><a href="http://localhost/compose/env">Compose environment variables</a></li>
|
||
<li><a href="http://localhost/compose/completion">Compose command line completion</a></li>
|
||
</ul>
|
||
|
||
<h2 id="quick-start">Quick start</h2>
|
||
|
||
<p>Let&rsquo;s get started with a walkthrough of getting a simple Python web app running
|
||
on Compose. It assumes a little knowledge of Python, but the concepts
|
||
demonstrated here should be understandable even if you&rsquo;re not familiar with
|
||
Python.</p>
|
||
|
||
<h3 id="installation-and-set-up">Installation and set-up</h3>
|
||
|
||
<p>First, <a href="http://localhost/compose/install">install Docker and Compose</a>.</p>
|
||
|
||
<p>Next, you&rsquo;ll want to make a directory for the project:</p>
|
||
|
||
<pre><code>$ mkdir composetest
|
||
$ cd composetest
|
||
</code></pre>
|
||
|
||
<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>
|
||
|
||
<pre><code>from flask import Flask
|
||
from redis import Redis
|
||
import os
|
||
app = Flask(__name__)
|
||
redis = Redis(host='redis', port=6379)
|
||
|
||
@app.route('/')
|
||
def hello():
|
||
redis.incr('hits')
|
||
return 'Hello World! I have been seen %s times.' % redis.get('hits')
|
||
|
||
if __name__ == &quot;__main__&quot;:
|
||
app.run(host=&quot;0.0.0.0&quot;, debug=True)
|
||
</code></pre>
|
||
|
||
<p>Next, define the Python dependencies in a file called <code>requirements.txt</code>:</p>
|
||
|
||
<pre><code>flask
|
||
redis
|
||
</code></pre>
|
||
|
||
<h3 id="create-a-docker-image">Create a Docker image</h3>
|
||
|
||
<p>Now, create a Docker image containing all of your app&rsquo;s dependencies. You
|
||
specify how to build the image using a file called
|
||
<a href="http://docs.docker.com/reference/builder/"><code>Dockerfile</code></a>:</p>
|
||
|
||
<pre><code>FROM python:2.7
|
||
ADD . /code
|
||
WORKDIR /code
|
||
RUN pip install -r requirements.txt
|
||
CMD python app.py
|
||
</code></pre>
|
||
|
||
<p>This tells Docker to:</p>
|
||
|
||
<ul>
|
||
<li>Build an image starting with the Python 2.7 image.</li>
|
||
<li>Add the current directory <code>.</code> into the path <code>/code</code> in the image.</li>
|
||
<li>Set the working directory to <code>/code</code>.</li>
|
||
<li>Install your Python dependencies.</li>
|
||
<li>Set the default command for the container to <code>python app.py</code></li>
|
||
</ul>
|
||
|
||
<p>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="http://docs.docker.com/reference/builder/">Dockerfile reference</a>.</p>
|
||
|
||
<p>You can test that this builds by running <code>docker build -t web .</code>.</p>
|
||
|
||
<h3 id="define-services">Define services</h3>
|
||
|
||
<p>Next, define a set of services using <code>docker-compose.yml</code>:</p>
|
||
|
||
<pre><code>web:
|
||
build: .
|
||
ports:
|
||
- &quot;5000:5000&quot;
|
||
volumes:
|
||
- .:/code
|
||
links:
|
||
- redis
|
||
redis:
|
||
image: redis
|
||
</code></pre>
|
||
|
||
<p>This defines two services:</p>
|
||
|
||
<h4 id="web">web</h4>
|
||
|
||
<ul>
|
||
<li>Builds from the <code>Dockerfile</code> in the current directory.</li>
|
||
<li>Forwards the exposed port 5000 on the container to port 5000 on the host machine.</li>
|
||
<li>Connects the web container to the Redis service via a link.</li>
|
||
<li>Mounts the current directory on the host to <code>/code</code> inside the container allowing you to modify the code without having to rebuild the image.</li>
|
||
</ul>
|
||
|
||
<h4 id="redis">redis</h4>
|
||
|
||
<ul>
|
||
<li>Uses the public <a href="https://registry.hub.docker.com/_/redis/">Redis</a> image which gets pulled from the Docker Hub registry.</li>
|
||
</ul>
|
||
|
||
<h3 id="build-and-run-your-app-with-compose">Build and run your app with Compose</h3>
|
||
|
||
<p>Now, when you run <code>docker-compose up</code>, Compose will pull a Redis image, build an image for your code, and start everything up:</p>
|
||
|
||
<pre><code>$ docker-compose up
|
||
Pulling image redis...
|
||
Building web...
|
||
Starting composetest_redis_1...
|
||
Starting composetest_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>
|
||
|
||
<p>The web app should now be listening on port 5000 on your Docker daemon host (if
|
||
you&rsquo;re using Boot2docker, <code>boot2docker ip</code> will tell you its address). In a browser,
|
||
open <code>http://ip-from-boot2docker:5000</code> and you should get a message in your browser saying:</p>
|
||
|
||
<p><code>Hello World! I have been seen 1 times.</code></p>
|
||
|
||
<p>Refreshing the page will increment the number.</p>
|
||
|
||
<p>If you want to run your services in the background, you can pass the <code>-d</code> flag
|
||
(for &ldquo;detached&rdquo; mode) to <code>docker-compose up</code> and use <code>docker-compose ps</code> to
|
||
see what is currently running:</p>
|
||
|
||
<pre><code>$ docker-compose up -d
|
||
Starting composetest_redis_1...
|
||
Starting composetest_web_1...
|
||
$ docker-compose ps
|
||
Name Command State Ports
|
||
-------------------------------------------------------------------
|
||
composetest_redis_1 /usr/local/bin/run Up
|
||
composetest_web_1 /bin/sh -c python app.py Up 5000-&gt;5000/tcp
|
||
</code></pre>
|
||
|
||
<p>The <code>docker-compose run</code> command 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>
|
||
|
||
<pre><code>$ docker-compose run web env
|
||
</code></pre>
|
||
|
||
<p>See <code>docker-compose --help</code> to see other available commands.</p>
|
||
|
||
<p>If you started Compose with <code>docker-compose up -d</code>, you&rsquo;ll probably want to stop
|
||
your services once you&rsquo;ve finished with them:</p>
|
||
|
||
<pre><code>$ docker-compose stop
|
||
</code></pre>
|
||
|
||
<p>At this point, you have seen the basics of how Compose works.</p>
|
||
|
||
<ul>
|
||
<li>Next, try the quick start guide for <a href="http://localhost/compose/django">Django</a>,
|
||
<a href="http://localhost/compose/rails">Rails</a>, or <a href="wordpress">Wordpress</a>.</li>
|
||
<li>See the reference guides for complete details on the <a href="http://localhost/compose/cli">commands</a>, the
|
||
<a href="http://localhost/compose/yml">configuration file</a> and <a href="env">environment variables</a>.</li>
|
||
</ul>
|
||
|
||
<h2 id="release-notes">Release Notes</h2>
|
||
|
||
<h3 id="version-1-2-0-april-7-2015">Version 1.2.0 (April 7, 2015)</h3>
|
||
|
||
<p>For complete information on this release, see the <a href="https://github.com/docker/compose/wiki/1.2.0-Milestone-Project-Page">1.2.0 Milestone project page</a>.
|
||
In addition to bug fixes and refinements, this release adds the following:</p>
|
||
|
||
<ul>
|
||
<li><p>The <code>extends</code> keyword, which adds the ability to extend services by sharing common configurations. For details, see
|
||
<a href="https://github.com/docker/compose/pull/1088">PR #1088</a>.</p></li>
|
||
|
||
<li><p>Better integration with Swarm. Swarm will now schedule inter-dependent
|
||
containers on the same host. For details, see
|
||
<a href="https://github.com/docker/compose/pull/972">PR #972</a>.</p></li>
|
||
</ul>
|
||
|
||
<h2 id="getting-help">Getting help</h2>
|
||
|
||
<p>Docker Compose is still in its infancy and under active development. If you need
|
||
help, would like to contribute, or simply want to talk about the project with
|
||
like-minded individuals, we have a number of open channels for communication.</p>
|
||
|
||
<ul>
|
||
<li><p>To report bugs or file feature requests: please use the <a href="https://github.com/docker/compose/issues">issue tracker on Github</a>.</p></li>
|
||
|
||
<li><p>To talk about the project with people in real time: please join the <code>#docker-compose</code> channel on IRC.</p></li>
|
||
|
||
<li><p>To contribute code or documentation changes: please submit a <a href="https://github.com/docker/compose/pulls">pull request on Github</a>.</p></li>
|
||
</ul>
|
||
|
||
<p>For more information and resources, please visit the <a href="https://docs.docker.com/project/get-help/">Getting Help project page</a>.</p>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Quickstart Guide: Compose and Django</title>
|
||
<link>http://localhost/compose/django/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/django/</guid>
|
||
<description>
|
||
|
||
<h2 id="quickstart-guide-compose-and-django">Quickstart Guide: Compose and Django</h2>
|
||
|
||
<p>This Quick-start Guide will demonstrate how to use Compose to set up and run a
|
||
simple Django/PostgreSQL app. Before starting, you&rsquo;ll need to have
|
||
<a href="http://localhost/compose/install">Compose installed</a>.</p>
|
||
|
||
<h3 id="define-the-project">Define the project</h3>
|
||
|
||
<p>Start by setting up the three files you&rsquo;ll need to build the app. First, since
|
||
your app is going to run inside a Docker container containing all of its
|
||
dependencies, you&rsquo;ll need to define exactly what needs to be included in the
|
||
container. This is done using a file called <code>Dockerfile</code>. To begin with, the
|
||
Dockerfile consists of:</p>
|
||
|
||
<pre><code>FROM python:2.7
|
||
ENV PYTHONUNBUFFERED 1
|
||
RUN mkdir /code
|
||
WORKDIR /code
|
||
ADD requirements.txt /code/
|
||
RUN pip install -r requirements.txt
|
||
ADD . /code/
|
||
</code></pre>
|
||
|
||
<p>This Dockerfile will define an image that is used to build a container that
|
||
includes your application and has Python installed alongside all of your Python
|
||
dependencies. 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="http://docs.docker.com/reference/builder/">Dockerfile reference</a>.</p>
|
||
|
||
<p>Second, you&rsquo;ll define your Python dependencies in a file called
|
||
<code>requirements.txt</code>:</p>
|
||
|
||
<pre><code>Django
|
||
psycopg2
|
||
</code></pre>
|
||
|
||
<p>Finally, this is all tied together with a file called <code>docker-compose.yml</code>. It
|
||
describes the services that comprise your app (here, a web server and database),
|
||
which Docker images they use, how they link together, what volumes will be
|
||
mounted inside the containers, and what ports they expose.</p>
|
||
|
||
<pre><code>db:
|
||
image: postgres
|
||
web:
|
||
build: .
|
||
command: python manage.py runserver 0.0.0.0:8000
|
||
volumes:
|
||
- .:/code
|
||
ports:
|
||
- &quot;8000:8000&quot;
|
||
links:
|
||
- db
|
||
</code></pre>
|
||
|
||
<p>See the <a href="yml.html"><code>docker-compose.yml</code> reference</a> for more information on how
|
||
this file works.</p>
|
||
|
||
<h3 id="build-the-project">Build the project</h3>
|
||
|
||
<p>You can now start a Django project with <code>docker-compose run</code>:</p>
|
||
|
||
<pre><code>$ docker-compose run web django-admin.py startproject composeexample .
|
||
</code></pre>
|
||
|
||
<p>First, Compose will build an image for the <code>web</code> service using the <code>Dockerfile</code>.
|
||
It will then run <code>django-admin.py startproject composeexample .</code> inside a
|
||
container built using that image.</p>
|
||
|
||
<p>This will generate a Django app inside the current directory:</p>
|
||
|
||
<pre><code>$ ls
|
||
Dockerfile docker-compose.yml composeexample manage.py requirements.txt
|
||
</code></pre>
|
||
|
||
<h3 id="connect-the-database">Connect the database</h3>
|
||
|
||
<p>Now you need to set up the database connection. Replace the <code>DATABASES = ...</code>
|
||
definition in <code>composeexample/settings.py</code> to read:</p>
|
||
|
||
<pre><code>DATABASES = {
|
||
'default': {
|
||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||
'NAME': 'postgres',
|
||
'USER': 'postgres',
|
||
'HOST': 'db',
|
||
'PORT': 5432,
|
||
}
|
||
}
|
||
</code></pre>
|
||
|
||
<p>These settings are determined by the
|
||
<a href="https://registry.hub.docker.com/_/postgres/">postgres</a> Docker image specified
|
||
in the Dockerfile.</p>
|
||
|
||
<p>Then, run <code>docker-compose up</code>:</p>
|
||
|
||
<pre><code>Recreating myapp_db_1...
|
||
Recreating myapp_web_1...
|
||
Attaching to myapp_db_1, myapp_web_1
|
||
myapp_db_1 |
|
||
myapp_db_1 | PostgreSQL stand-alone backend 9.1.11
|
||
myapp_db_1 | 2014-01-27 12:17:03 UTC LOG: database system is ready to accept connections
|
||
myapp_db_1 | 2014-01-27 12:17:03 UTC LOG: autovacuum launcher started
|
||
myapp_web_1 | Validating models...
|
||
myapp_web_1 |
|
||
myapp_web_1 | 0 errors found
|
||
myapp_web_1 | January 27, 2014 - 12:12:40
|
||
myapp_web_1 | Django version 1.6.1, using settings 'composeexample.settings'
|
||
myapp_web_1 | Starting development server at http://0.0.0.0:8000/
|
||
myapp_web_1 | Quit the server with CONTROL-C.
|
||
</code></pre>
|
||
|
||
<p>Your Django app should nw be running at port 8000 on your Docker daemon (if
|
||
you&rsquo;re using Boot2docker, <code>boot2docker ip</code> will tell you its address).</p>
|
||
|
||
<p>You can also run management commands with Docker. To set up your database, for
|
||
example, run <code>docker-compose up</code> and in another terminal run:</p>
|
||
|
||
<pre><code>$ docker-compose run web python manage.py syncdb
|
||
</code></pre>
|
||
|
||
<h2 id="more-compose-documentation">More Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/">User guide</a></li>
|
||
<li><a href="http://localhost/compose/install">Installing Compose</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/cli">Command line reference</a></li>
|
||
<li><a href="http://localhost/compose/yml">Yaml file reference</a></li>
|
||
<li><a href="http://localhost/compose/env">Compose environment variables</a></li>
|
||
<li><a href="http://localhost/compose/completion">Compose command line completion</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Quickstart Guide: Compose and Rails</title>
|
||
<link>http://localhost/compose/rails/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/rails/</guid>
|
||
<description>
|
||
|
||
<h2 id="quickstart-guide-compose-and-rails">Quickstart Guide: Compose and Rails</h2>
|
||
|
||
<p>This Quickstart guide will show you how to use Compose to set up and run a Rails/PostgreSQL app. Before starting, you&rsquo;ll need to have <a href="http://localhost/compose/install">Compose installed</a>.</p>
|
||
|
||
<h3 id="define-the-project">Define the project</h3>
|
||
|
||
<p>Start by setting up the three files you&rsquo;ll need to build the app. First, since
|
||
your app is going to run inside a Docker container containing all of its
|
||
dependencies, you&rsquo;ll need to define exactly what needs to be included in the
|
||
container. This is done using a file called <code>Dockerfile</code>. To begin with, the
|
||
Dockerfile consists of:</p>
|
||
|
||
<pre><code>FROM ruby:2.2.0
|
||
RUN apt-get update -qq &amp;&amp; apt-get install -y build-essential libpq-dev
|
||
RUN mkdir /myapp
|
||
WORKDIR /myapp
|
||
ADD Gemfile /myapp/Gemfile
|
||
RUN bundle install
|
||
ADD . /myapp
|
||
</code></pre>
|
||
|
||
<p>That&rsquo;ll put your application code inside an image that will build a container with Ruby, Bundler and all your dependencies inside it. 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="http://docs.docker.com/reference/builder/">Dockerfile reference</a>.</p>
|
||
|
||
<p>Next, create a bootstrap <code>Gemfile</code> which just loads Rails. It&rsquo;ll be overwritten in a moment by <code>rails new</code>.</p>
|
||
|
||
<pre><code>source 'https://rubygems.org'
|
||
gem 'rails', '4.2.0'
|
||
</code></pre>
|
||
|
||
<p>Finally, <code>docker-compose.yml</code> is where the magic happens. This file describes the services that comprise your app (a database and a web app), how to get each one&rsquo;s Docker image (the database just runs on a pre-made PostgreSQL image, and the web app is built from the current directory), and the configuration needed to link them together and expose the web app&rsquo;s port.</p>
|
||
|
||
<pre><code>db:
|
||
image: postgres
|
||
ports:
|
||
- &quot;5432&quot;
|
||
web:
|
||
build: .
|
||
command: bundle exec rails s -p 3000 -b '0.0.0.0'
|
||
volumes:
|
||
- .:/myapp
|
||
ports:
|
||
- &quot;3000:3000&quot;
|
||
links:
|
||
- db
|
||
</code></pre>
|
||
|
||
<h3 id="build-the-project">Build the project</h3>
|
||
|
||
<p>With those three files in place, you can now generate the Rails skeleton app
|
||
using <code>docker-compose run</code>:</p>
|
||
|
||
<pre><code>$ docker-compose run web rails new . --force --database=postgresql --skip-bundle
|
||
</code></pre>
|
||
|
||
<p>First, Compose will build the image for the <code>web</code> service using the
|
||
<code>Dockerfile</code>. Then it&rsquo;ll run <code>rails new</code> inside a new container, using that
|
||
image. Once it&rsquo;s done, you should have generated a fresh app:</p>
|
||
|
||
<pre><code>$ ls
|
||
Dockerfile app docker-compose.yml tmp
|
||
Gemfile bin lib vendor
|
||
Gemfile.lock config log
|
||
README.rdoc config.ru public
|
||
Rakefile db test
|
||
</code></pre>
|
||
|
||
<p>Uncomment the line in your new <code>Gemfile</code> which loads <code>therubyracer</code>, so you&rsquo;ve
|
||
got a Javascript runtime:</p>
|
||
|
||
<pre><code>gem 'therubyracer', platforms: :ruby
|
||
</code></pre>
|
||
|
||
<p>Now that you&rsquo;ve got a new <code>Gemfile</code>, you need to build the image again. (This,
|
||
and changes to the Dockerfile itself, should be the only times you&rsquo;ll need to
|
||
rebuild.)</p>
|
||
|
||
<pre><code>$ docker-compose build
|
||
</code></pre>
|
||
|
||
<h3 id="connect-the-database">Connect the database</h3>
|
||
|
||
<p>The app is now bootable, but you&rsquo;re not quite there yet. By default, Rails
|
||
expects a database to be running on <code>localhost</code> - so you need to point it at the
|
||
<code>db</code> container instead. You also need to change the database and username to
|
||
align with the defaults set by the <code>postgres</code> image.</p>
|
||
|
||
<p>Open up your newly-generated <code>database.yml</code> file. Replace its contents with the
|
||
following:</p>
|
||
|
||
<pre><code>development: &amp;default
|
||
adapter: postgresql
|
||
encoding: unicode
|
||
database: postgres
|
||
pool: 5
|
||
username: postgres
|
||
password:
|
||
host: db
|
||
|
||
test:
|
||
&lt;&lt;: *default
|
||
database: myapp_test
|
||
</code></pre>
|
||
|
||
<p>You can now boot the app with:</p>
|
||
|
||
<pre><code>$ docker-compose up
|
||
</code></pre>
|
||
|
||
<p>If all&rsquo;s well, you should see some PostgreSQL output, and then—after a few
|
||
seconds—the familiar refrain:</p>
|
||
|
||
<pre><code>myapp_web_1 | [2014-01-17 17:16:29] INFO WEBrick 1.3.1
|
||
myapp_web_1 | [2014-01-17 17:16:29] INFO ruby 2.2.0 (2014-12-25) [x86_64-linux-gnu]
|
||
myapp_web_1 | [2014-01-17 17:16:29] INFO WEBrick::HTTPServer#start: pid=1 port=3000
|
||
</code></pre>
|
||
|
||
<p>Finally, you need to create the database. In another terminal, run:</p>
|
||
|
||
<pre><code>$ docker-compose run web rake db:create
|
||
</code></pre>
|
||
|
||
<p>That&rsquo;s it. Your app should now be running on port 3000 on your Docker daemon (if
|
||
you&rsquo;re using Boot2docker, <code>boot2docker ip</code> will tell you its address).</p>
|
||
|
||
<h2 id="more-compose-documentation">More Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/">User guide</a></li>
|
||
<li><a href="http://localhost/compose/install">Installing Compose</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/cli">Command line reference</a></li>
|
||
<li><a href="http://localhost/compose/yml">Yaml file reference</a></li>
|
||
<li><a href="http://localhost/compose/env">Compose environment variables</a></li>
|
||
<li><a href="http://localhost/compose/completion">Compose command line completion</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Quickstart Guide: Compose and Wordpress</title>
|
||
<link>http://localhost/compose/wordpress/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/wordpress/</guid>
|
||
<description>
|
||
|
||
<h1 id="quickstart-guide-compose-and-wordpress">Quickstart Guide: Compose and Wordpress</h1>
|
||
|
||
<p>You can use Compose to easily run Wordpress in an isolated environment built
|
||
with Docker containers.</p>
|
||
|
||
<h2 id="define-the-project">Define the project</h2>
|
||
|
||
<p>First, <a href="http://localhost/compose/install">Install Compose</a> and then download Wordpress into the
|
||
current directory:</p>
|
||
|
||
<pre><code>$ curl https://wordpress.org/latest.tar.gz | tar -xvzf -
|
||
</code></pre>
|
||
|
||
<p>This will create a directory called <code>wordpress</code>. If you wish, you can rename it
|
||
to the name of your project.</p>
|
||
|
||
<p>Next, inside that directory, create a <code>Dockerfile</code>, a file that defines what
|
||
environment your app is going to run in. 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="http://docs.docker.com/reference/builder/">Dockerfile reference</a>. In this case,
|
||
your Dockerfile should be:</p>
|
||
|
||
<pre><code>FROM orchardup/php5
|
||
ADD . /code
|
||
</code></pre>
|
||
|
||
<p>This tells Docker how to build an image defining a container that contains PHP
|
||
and Wordpress.</p>
|
||
|
||
<p>Next you&rsquo;ll create a <code>docker-compose.yml</code> file that will start your web service
|
||
and a separate MySQL instance:</p>
|
||
|
||
<pre><code>web:
|
||
build: .
|
||
command: php -S 0.0.0.0:8000 -t /code
|
||
ports:
|
||
- &quot;8000:8000&quot;
|
||
links:
|
||
- db
|
||
volumes:
|
||
- .:/code
|
||
db:
|
||
image: orchardup/mysql
|
||
environment:
|
||
MYSQL_DATABASE: wordpress
|
||
</code></pre>
|
||
|
||
<p>Two supporting files are needed to get this working - first, <code>wp-config.php</code> is
|
||
the standard Wordpress config file with a single change to point the database
|
||
configuration at the <code>db</code> container:</p>
|
||
|
||
<pre><code>&lt;?php
|
||
define('DB_NAME', 'wordpress');
|
||
define('DB_USER', 'root');
|
||
define('DB_PASSWORD', '');
|
||
define('DB_HOST', &quot;db:3306&quot;);
|
||
define('DB_CHARSET', 'utf8');
|
||
define('DB_COLLATE', '');
|
||
|
||
define('AUTH_KEY', 'put your unique phrase here');
|
||
define('SECURE_AUTH_KEY', 'put your unique phrase here');
|
||
define('LOGGED_IN_KEY', 'put your unique phrase here');
|
||
define('NONCE_KEY', 'put your unique phrase here');
|
||
define('AUTH_SALT', 'put your unique phrase here');
|
||
define('SECURE_AUTH_SALT', 'put your unique phrase here');
|
||
define('LOGGED_IN_SALT', 'put your unique phrase here');
|
||
define('NONCE_SALT', 'put your unique phrase here');
|
||
|
||
$table_prefix = 'wp_';
|
||
define('WPLANG', '');
|
||
define('WP_DEBUG', false);
|
||
|
||
if ( !defined('ABSPATH') )
|
||
define('ABSPATH', dirname(__FILE__) . '/');
|
||
|
||
require_once(ABSPATH . 'wp-settings.php');
|
||
</code></pre>
|
||
|
||
<p>Second, <code>router.php</code> tells PHP&rsquo;s built-in web server how to run Wordpress:</p>
|
||
|
||
<pre><code>&lt;?php
|
||
|
||
$root = $_SERVER['DOCUMENT_ROOT'];
|
||
chdir($root);
|
||
$path = '/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'/');
|
||
set_include_path(get_include_path().':'.__DIR__);
|
||
if(file_exists($root.$path))
|
||
{
|
||
if(is_dir($root.$path) &amp;&amp; substr($path,strlen($path) - 1, 1) !== '/')
|
||
$path = rtrim($path,'/').'/index.php';
|
||
if(strpos($path,'.php') === false) return false;
|
||
else {
|
||
chdir(dirname($root.$path));
|
||
require_once $root.$path;
|
||
}
|
||
}else include_once 'index.php';
|
||
</code></pre>
|
||
|
||
<h3 id="build-the-project">Build the project</h3>
|
||
|
||
<p>With those four files in place, run <code>docker-compose up</code> inside your Wordpress
|
||
directory and it&rsquo;ll pull and build the needed images, and then start the web and
|
||
database containers. You&rsquo;ll then be able to visit Wordpress at port 8000 on your
|
||
Docker daemon (if you&rsquo;re using Boot2docker, <code>boot2docker ip</code> will tell you its
|
||
address).</p>
|
||
|
||
<h2 id="more-compose-documentation">More Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/">User guide</a></li>
|
||
<li><a href="http://localhost/compose/install">Installing Compose</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/cli">Command line reference</a></li>
|
||
<li><a href="http://localhost/compose/yml">Yaml file reference</a></li>
|
||
<li><a href="http://localhost/compose/env">Compose environment variables</a></li>
|
||
<li><a href="http://localhost/compose/completion">Compose command line completion</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Using Compose in production</title>
|
||
<link>http://localhost/compose/production/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/production/</guid>
|
||
<description>
|
||
|
||
<h2 id="using-compose-in-production">Using Compose in production</h2>
|
||
|
||
<p>While <strong>Compose is not yet considered production-ready</strong>, if you&rsquo;d like to experiment and learn more about using it in production deployments, this guide
|
||
can help.
|
||
The project is actively working towards becoming
|
||
production-ready; to learn more about the progress being made, check out the
|
||
<a href="http://localhost/compose/https://github.com/docker/compose/blob/master/ROADMAP">roadmap</a> for details
|
||
on how it&rsquo;s coming along and what still needs to be done.</p>
|
||
|
||
<p>When deploying to production, you&rsquo;ll almost certainly want to make changes to
|
||
your app configuration that are more appropriate to a live environment. These
|
||
changes may include:</p>
|
||
|
||
<ul>
|
||
<li>Removing any volume bindings for application code, so that code stays inside
|
||
the container and can&rsquo;t be changed from outside</li>
|
||
<li>Binding to different ports on the host</li>
|
||
<li>Setting environment variables differently (e.g., to decrease the verbosity of
|
||
logging, or to enable email sending)</li>
|
||
<li>Specifying a restart policy (e.g., <code>restart: always</code>) to avoid downtime</li>
|
||
<li>Adding extra services (e.g., a log aggregator)</li>
|
||
</ul>
|
||
|
||
<p>For this reason, you&rsquo;ll probably want to define a separate Compose file, say
|
||
<code>production.yml</code>, which specifies production-appropriate configuration.</p>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> The <a href="http://localhost/compose/extends">extends</a> keyword is useful for maintaining multiple
|
||
Compose files which re-use common services without having to manually copy and
|
||
paste.</p>
|
||
</blockquote>
|
||
|
||
<p>Once you&rsquo;ve got an alternate configuration file, make Compose use it
|
||
by setting the <code>COMPOSE_FILE</code> environment variable:</p>
|
||
|
||
<pre><code>$ COMPOSE_FILE=production.yml
|
||
$ docker-compose up -d
|
||
</code></pre>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> You can also use the file for a one-off command without setting
|
||
an environment variable. You do this by passing the <code>-f</code> flag, e.g.,
|
||
<code>docker-compose -f production.yml up -d</code>.</p>
|
||
</blockquote>
|
||
|
||
<h3 id="deploying-changes">Deploying changes</h3>
|
||
|
||
<p>When you make changes to your app code, you&rsquo;ll need to rebuild your image and
|
||
recreate your app&rsquo;s containers. To redeploy a service called
|
||
<code>web</code>, you would use:</p>
|
||
|
||
<pre><code>$ docker-compose build web
|
||
$ docker-compose up --no-deps -d web
|
||
</code></pre>
|
||
|
||
<p>This will first rebuild the image for <code>web</code> and then stop, destroy, and recreate
|
||
<em>just</em> the <code>web</code> service. The <code>--no-deps</code> flag prevents Compose from also
|
||
recreating any services which <code>web</code> depends on.</p>
|
||
|
||
<h3 id="running-compose-on-a-single-server">Running Compose on a single server</h3>
|
||
|
||
<p>You can use Compose to deploy an app to a remote Docker host by setting the
|
||
<code>DOCKER_HOST</code>, <code>DOCKER_TLS_VERIFY</code>, and <code>DOCKER_CERT_PATH</code> environment variables
|
||
appropriately. For tasks like this,
|
||
<a href="https://docs.docker.com/machine">Docker Machine</a> makes managing local and
|
||
remote Docker hosts very easy, and is recommended even if you&rsquo;re not deploying
|
||
remotely.</p>
|
||
|
||
<p>Once you&rsquo;ve set up your environment variables, all the normal <code>docker-compose</code>
|
||
commands will work with no further configuration.</p>
|
||
|
||
<h3 id="running-compose-on-a-swarm-cluster">Running Compose on a Swarm cluster</h3>
|
||
|
||
<p><a href="https://docs.docker.com/swarm">Docker Swarm</a>, a Docker-native clustering
|
||
system, exposes the same API as a single Docker host, which means you can use
|
||
Compose against a Swarm instance and run your apps across multiple hosts.</p>
|
||
|
||
<p>Compose/Swarm integration is still in the experimental stage, and Swarm is still
|
||
in beta, but if you&rsquo;d like to explore and experiment, check out the
|
||
<a href="http://localhost/compose/https://github.com/docker/compose/blob/master/SWARM">integration guide</a>.</p>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/install">Installing Compose</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/cli">Command line reference</a></li>
|
||
<li><a href="http://localhost/compose/yml">Yaml file reference</a></li>
|
||
<li><a href="http://localhost/compose/env">Compose environment variables</a></li>
|
||
<li><a href="http://localhost/compose/completion">Compose command line completion</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>docker-compose.yml reference</title>
|
||
<link>http://localhost/compose/yml/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://localhost/compose/yml/</guid>
|
||
<description>
|
||
|
||
<h1 id="docker-compose-yml-reference">docker-compose.yml reference</h1>
|
||
|
||
<p>Each service defined in <code>docker-compose.yml</code> must specify exactly one of
|
||
<code>image</code> or <code>build</code>. Other keys are optional, and are analogous to their
|
||
<code>docker run</code> command-line counterparts.</p>
|
||
|
||
<p>As with <code>docker run</code>, options specified in the Dockerfile (e.g., <code>CMD</code>,
|
||
<code>EXPOSE</code>, <code>VOLUME</code>, <code>ENV</code>) are respected by default - you don&rsquo;t need to
|
||
specify them again in <code>docker-compose.yml</code>.</p>
|
||
|
||
<h3 id="image">image</h3>
|
||
|
||
<p>Tag or partial image ID. Can be local or remote - Compose will attempt to
|
||
pull if it doesn&rsquo;t exist locally.</p>
|
||
|
||
<pre><code>image: ubuntu
|
||
image: orchardup/postgresql
|
||
image: a4bc65fd
|
||
</code></pre>
|
||
|
||
<h3 id="build">build</h3>
|
||
|
||
<p>Path to a directory containing a Dockerfile. When the value supplied is a
|
||
relative path, it is interpreted as relative to the location of the yml file
|
||
itself. This directory is also the build context that is sent to the Docker daemon.</p>
|
||
|
||
<p>Compose will build and tag it with a generated name, and use that image thereafter.</p>
|
||
|
||
<pre><code>build: /path/to/build/dir
|
||
</code></pre>
|
||
|
||
<h3 id="dockerfile">dockerfile</h3>
|
||
|
||
<p>Alternate Dockerfile.</p>
|
||
|
||
<p>Compose will use an alternate file to build with.</p>
|
||
|
||
<pre><code>dockerfile: Dockerfile-alternate
|
||
</code></pre>
|
||
|
||
<h3 id="command">command</h3>
|
||
|
||
<p>Override the default command.</p>
|
||
|
||
<pre><code>command: bundle exec thin -p 3000
|
||
</code></pre>
|
||
|
||
<p><a name="links"></a></p>
|
||
|
||
<h3 id="links">links</h3>
|
||
|
||
<p>Link to containers in another service. Either specify both the service name and
|
||
the link alias (<code>SERVICE:ALIAS</code>), or just the service name (which will also be
|
||
used for the alias).</p>
|
||
|
||
<pre><code>links:
|
||
- db
|
||
- db:database
|
||
- redis
|
||
</code></pre>
|
||
|
||
<p>An entry with the alias&rsquo; name will be created in <code>/etc/hosts</code> inside containers
|
||
for this service, e.g:</p>
|
||
|
||
<pre><code>172.17.2.186 db
|
||
172.17.2.186 database
|
||
172.17.2.187 redis
|
||
</code></pre>
|
||
|
||
<p>Environment variables will also be created - see the <a href="http://localhost/compose/env">environment variable
|
||
reference</a> for details.</p>
|
||
|
||
<h3 id="external-links">external_links</h3>
|
||
|
||
<p>Link to containers started outside this <code>docker-compose.yml</code> or even outside
|
||
of Compose, especially for containers that provide shared or common services.
|
||
<code>external_links</code> follow semantics similar to <code>links</code> when specifying both the
|
||
container name and the link alias (<code>CONTAINER:ALIAS</code>).</p>
|
||
|
||
<pre><code>external_links:
|
||
- redis_1
|
||
- project_db_1:mysql
|
||
- project_db_1:postgresql
|
||
</code></pre>
|
||
|
||
<h3 id="extra-hosts">extra_hosts</h3>
|
||
|
||
<p>Add hostname mappings. Use the same values as the docker client <code>--add-host</code> parameter.</p>
|
||
|
||
<pre><code>extra_hosts:
|
||
- &quot;somehost:162.242.195.82&quot;
|
||
- &quot;otherhost:50.31.209.229&quot;
|
||
</code></pre>
|
||
|
||
<p>An entry with the ip address and hostname will be created in <code>/etc/hosts</code> inside containers for this service, e.g:</p>
|
||
|
||
<pre><code>162.242.195.82 somehost
|
||
50.31.209.229 otherhost
|
||
</code></pre>
|
||
|
||
<h3 id="ports">ports</h3>
|
||
|
||
<p>Expose ports. Either specify both ports (<code>HOST:CONTAINER</code>), or just the container
|
||
port (a random host port will be chosen).</p>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> When mapping ports in the <code>HOST:CONTAINER</code> format, you may experience
|
||
erroneous results when using a container port lower than 60, because YAML will
|
||
parse numbers in the format <code>xx:yy</code> as sexagesimal (base 60). For this reason,
|
||
we recommend always explicitly specifying your port mappings as strings.</p>
|
||
</blockquote>
|
||
|
||
<pre><code>ports:
|
||
- &quot;3000&quot;
|
||
- &quot;8000:8000&quot;
|
||
- &quot;49100:22&quot;
|
||
- &quot;127.0.0.1:8001:8001&quot;
|
||
</code></pre>
|
||
|
||
<h3 id="expose">expose</h3>
|
||
|
||
<p>Expose ports without publishing them to the host machine - they&rsquo;ll only be
|
||
accessible to linked services. Only the internal port can be specified.</p>
|
||
|
||
<pre><code>expose:
|
||
- &quot;3000&quot;
|
||
- &quot;8000&quot;
|
||
</code></pre>
|
||
|
||
<h3 id="volumes">volumes</h3>
|
||
|
||
<p>Mount paths as volumes, optionally specifying a path on the host machine
|
||
(<code>HOST:CONTAINER</code>), or an access mode (<code>HOST:CONTAINER:ro</code>).</p>
|
||
|
||
<pre><code>volumes:
|
||
- /var/lib/mysql
|
||
- cache/:/tmp/cache
|
||
- ~/configs:/etc/configs/:ro
|
||
</code></pre>
|
||
|
||
<h3 id="volumes-from">volumes_from</h3>
|
||
|
||
<p>Mount all of the volumes from another service or container.</p>
|
||
|
||
<pre><code>volumes_from:
|
||
- service_name
|
||
- container_name
|
||
</code></pre>
|
||
|
||
<h3 id="environment">environment</h3>
|
||
|
||
<p>Add environment variables. You can use either an array or a dictionary.</p>
|
||
|
||
<p>Environment variables with only a key are resolved to their values on the
|
||
machine Compose is running on, which can be helpful for secret or host-specific values.</p>
|
||
|
||
<pre><code>environment:
|
||
RACK_ENV: development
|
||
SESSION_SECRET:
|
||
|
||
environment:
|
||
- RACK_ENV=development
|
||
- SESSION_SECRET
|
||
</code></pre>
|
||
|
||
<h3 id="env-file">env_file</h3>
|
||
|
||
<p>Add environment variables from a file. Can be a single value or a list.</p>
|
||
|
||
<p>If you have specified a Compose file with <code>docker-compose -f FILE</code>, paths in
|
||
<code>env_file</code> are relative to the directory that file is in.</p>
|
||
|
||
<p>Environment variables specified in <code>environment</code> override these values.</p>
|
||
|
||
<pre><code>env_file: .env
|
||
|
||
env_file:
|
||
- ./common.env
|
||
- ./apps/web.env
|
||
- /opt/secrets.env
|
||
</code></pre>
|
||
|
||
<p>Compose expects each line in an env file to be in <code>VAR=VAL</code> format. Lines
|
||
beginning with <code>#</code> (i.e. comments) are ignored, as are blank lines.</p>
|
||
|
||
<pre><code># Set Rails/Rack environment
|
||
RACK_ENV=development
|
||
</code></pre>
|
||
|
||
<h3 id="extends">extends</h3>
|
||
|
||
<p>Extend another service, in the current file or another, optionally overriding
|
||
configuration.</p>
|
||
|
||
<p>Here&rsquo;s a simple example. Suppose we have 2 files - <strong>common.yml</strong> and
|
||
<strong>development.yml</strong>. We can use <code>extends</code> to define a service in
|
||
<strong>development.yml</strong> which uses configuration defined in <strong>common.yml</strong>:</p>
|
||
|
||
<p><strong>common.yml</strong></p>
|
||
|
||
<pre><code>webapp:
|
||
build: ./webapp
|
||
environment:
|
||
- DEBUG=false
|
||
- SEND_EMAILS=false
|
||
</code></pre>
|
||
|
||
<p><strong>development.yml</strong></p>
|
||
|
||
<pre><code>web:
|
||
extends:
|
||
file: common.yml
|
||
service: webapp
|
||
ports:
|
||
- &quot;8000:8000&quot;
|
||
links:
|
||
- db
|
||
environment:
|
||
- DEBUG=true
|
||
db:
|
||
image: postgres
|
||
</code></pre>
|
||
|
||
<p>Here, the <code>web</code> service in <strong>development.yml</strong> inherits the configuration of
|
||
the <code>webapp</code> service in <strong>common.yml</strong> - the <code>build</code> and <code>environment</code> keys -
|
||
and adds <code>ports</code> and <code>links</code> configuration. It overrides one of the defined
|
||
environment variables (DEBUG) with a new value, and the other one
|
||
(SEND_EMAILS) is left untouched.</p>
|
||
|
||
<p>For more on <code>extends</code>, see the <a href="http://localhost/compose/extends#example">tutorial</a> and
|
||
<a href="http://localhost/compose/extends#reference">reference</a>.</p>
|
||
|
||
<h3 id="labels">labels</h3>
|
||
|
||
<p>Add metadata to containers using <a href="http://docs.docker.com/userguide/labels-custom-metadata/">Docker labels</a>. You can use either an array or a dictionary.</p>
|
||
|
||
<p>It&rsquo;s recommended that you use reverse-DNS notation to prevent your labels from conflicting with those used by other software.</p>
|
||
|
||
<pre><code>labels:
|
||
com.example.description: &quot;Accounting webapp&quot;
|
||
com.example.department: &quot;Finance&quot;
|
||
com.example.label-with-empty-value: &quot;&quot;
|
||
|
||
labels:
|
||
- &quot;com.example.description=Accounting webapp&quot;
|
||
- &quot;com.example.department=Finance&quot;
|
||
- &quot;com.example.label-with-empty-value&quot;
|
||
</code></pre>
|
||
|
||
<h3 id="log-driver">log driver</h3>
|
||
|
||
<p>Specify a logging driver for the service&rsquo;s containers, as with the <code>--log-driver</code> option for docker run (<a href="http://docs.docker.com/reference/run/#logging-drivers-log-driver">documented here</a>).</p>
|
||
|
||
<p>Allowed values are currently <code>json-file</code>, <code>syslog</code> and <code>none</code>. The list will change over time as more drivers are added to the Docker engine.</p>
|
||
|
||
<p>The default value is json-file.</p>
|
||
|
||
<pre><code>log_driver: &quot;json-file&quot;
|
||
log_driver: &quot;syslog&quot;
|
||
log_driver: &quot;none&quot;
|
||
</code></pre>
|
||
|
||
<h3 id="net">net</h3>
|
||
|
||
<p>Networking mode. Use the same values as the docker client <code>--net</code> parameter.</p>
|
||
|
||
<pre><code>net: &quot;bridge&quot;
|
||
net: &quot;none&quot;
|
||
net: &quot;container:[name or id]&quot;
|
||
net: &quot;host&quot;
|
||
</code></pre>
|
||
|
||
<h3 id="pid">pid</h3>
|
||
|
||
<pre><code>pid: &quot;host&quot;
|
||
</code></pre>
|
||
|
||
<p>Sets the PID mode to the host PID mode. This turns on sharing between
|
||
container and the host operating system the PID address space. Containers
|
||
launched with this flag will be able to access and manipulate other
|
||
containers in the bare-metal machine&rsquo;s namespace and vise-versa.</p>
|
||
|
||
<h3 id="dns">dns</h3>
|
||
|
||
<p>Custom DNS servers. Can be a single value or a list.</p>
|
||
|
||
<pre><code>dns: 8.8.8.8
|
||
dns:
|
||
- 8.8.8.8
|
||
- 9.9.9.9
|
||
</code></pre>
|
||
|
||
<h3 id="cap-add-cap-drop">cap_add, cap_drop</h3>
|
||
|
||
<p>Add or drop container capabilities.
|
||
See <code>man 7 capabilities</code> for a full list.</p>
|
||
|
||
<pre><code>cap_add:
|
||
- ALL
|
||
|
||
cap_drop:
|
||
- NET_ADMIN
|
||
- SYS_ADMIN
|
||
</code></pre>
|
||
|
||
<h3 id="dns-search">dns_search</h3>
|
||
|
||
<p>Custom DNS search domains. Can be a single value or a list.</p>
|
||
|
||
<pre><code>dns_search: example.com
|
||
dns_search:
|
||
- dc1.example.com
|
||
- dc2.example.com
|
||
</code></pre>
|
||
|
||
<h3 id="devices">devices</h3>
|
||
|
||
<p>List of device mappings. Uses the same format as the <code>--device</code> docker
|
||
client create option.</p>
|
||
|
||
<pre><code>devices:
|
||
- &quot;/dev/ttyUSB0:/dev/ttyUSB0&quot;
|
||
</code></pre>
|
||
|
||
<h3 id="security-opt">security_opt</h3>
|
||
|
||
<p>Override the default labeling scheme for each container.</p>
|
||
|
||
<pre><code> security_opt:
|
||
- label:user:USER
|
||
- label:role:ROLE
|
||
</code></pre>
|
||
|
||
<h3 id="working-dir-entrypoint-user-hostname-domainname-mem-limit-privileged-restart-stdin-open-tty-cpu-shares-cpuset-read-only">working_dir, entrypoint, user, hostname, domainname, mem_limit, privileged, restart, stdin_open, tty, cpu_shares, cpuset, read_only</h3>
|
||
|
||
<p>Each of these is a single value, analogous to its
|
||
<a href="https://docs.docker.com/reference/run/">docker run</a> counterpart.</p>
|
||
|
||
<pre><code>cpu_shares: 73
|
||
cpuset: 0,1
|
||
|
||
working_dir: /code
|
||
entrypoint: /code/entrypoint.sh
|
||
user: postgresql
|
||
|
||
hostname: foo
|
||
domainname: foo.com
|
||
|
||
mem_limit: 1000000000
|
||
privileged: true
|
||
|
||
restart: always
|
||
|
||
stdin_open: true
|
||
tty: true
|
||
read_only: true
|
||
</code></pre>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="http://localhost/compose/">User guide</a></li>
|
||
<li><a href="http://localhost/compose/install">Installing Compose</a></li>
|
||
<li><a href="http://localhost/compose/django">Get started with Django</a></li>
|
||
<li><a href="http://localhost/compose/rails">Get started with Rails</a></li>
|
||
<li><a href="http://localhost/compose/wordpress">Get started with Wordpress</a></li>
|
||
<li><a href="http://localhost/compose/cli">Command line reference</a></li>
|
||
<li><a href="http://localhost/compose/env">Compose environment variables</a></li>
|
||
<li><a href="http://localhost/compose/completion">Compose command line completion</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
</channel>
|
||
</rss> |