mirror of
https://github.com/docker/docs.git
synced 2026-03-27 14:28:47 +07:00
3060 lines
137 KiB
XML
3060 lines
137 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://docs-stage.docker.com/compose/</link>
|
||
<description>Recent content in Composes on Docker Docs</description>
|
||
<generator>Hugo -- gohugo.io</generator>
|
||
<language>en-us</language>
|
||
<atom:link href="http://docs-stage.docker.com/compose/index.xml" rel="self" type="application/rss+xml" />
|
||
|
||
<item>
|
||
<title>CLI Environment Variables</title>
|
||
<link>http://docs-stage.docker.com/compose/reference/envvars/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/reference/envvars/</guid>
|
||
<description>
|
||
|
||
<h1 id="cli-environment-variables">CLI Environment Variables</h1>
|
||
|
||
<p>Several environment variables are available for you to configure the Docker Compose command-line 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 <code>docker-machine</code>, then the <code>eval &quot;$(docker-machine env my-docker-vm)&quot;</code> command should set them to their correct values. (In this example, <code>my-docker-vm</code> is the name of a machine you created.)</p>
|
||
|
||
<blockquote>
|
||
<p>Note: Some of these variables can also be provided using an
|
||
<a href="../compose/env-file/">environment file</a></p>
|
||
</blockquote>
|
||
|
||
<h2 id="compose-project-name">COMPOSE_PROJECT_NAME</h2>
|
||
|
||
<p>Sets the project name. This value is prepended along with the service name to the container container on start up. For example, if you project name is <code>myapp</code> and it includes two services <code>db</code> and <code>web</code> then compose starts containers named <code>myapp_db_1</code> and <code>myapp_web_1</code> respectively.</p>
|
||
|
||
<p>Setting this is optional. If you do not set this, the <code>COMPOSE_PROJECT_NAME</code>
|
||
defaults to the <code>basename</code> of the project directory. See also the <code>-p</code>
|
||
<a href="../compose/reference/overview/">command-line option</a>.</p>
|
||
|
||
<h2 id="compose-file">COMPOSE_FILE</h2>
|
||
|
||
<p>Specify the path to a Compose file. If not provided, Compose looks for a file named
|
||
<code>docker-compose.yml</code> in the current directory and then each parent directory in
|
||
succession until a file by that name is found.</p>
|
||
|
||
<p>This variable supports multiple compose files separate by a path separator (on
|
||
Linux and OSX the path separator is <code>:</code>, on Windows it is <code>;</code>). For example:
|
||
<code>COMPOSE_FILE=docker-compose.yml:docker-compose.prod.yml</code></p>
|
||
|
||
<p>See also the <code>-f</code> <a href="../compose/reference/overview/">command-line option</a>.</p>
|
||
|
||
<h2 id="compose-api-version">COMPOSE_API_VERSION</h2>
|
||
|
||
<p>The Docker API only supports requests from clients which report a specific
|
||
version. If you receive a <code>client and server don't have same version error</code> using
|
||
<code>docker-compose</code>, you can workaround this error by setting this environment
|
||
variable. Set the version value to match the server version.</p>
|
||
|
||
<p>Setting this variable is intended as a workaround for situations where you need
|
||
to run temporarily with a mismatch between the client and server version. For
|
||
example, if you can upgrade the client but need to wait to upgrade the server.</p>
|
||
|
||
<p>Running with this variable set and a known mismatch does prevent some Docker
|
||
features from working properly. The exact features that fail would depend on the
|
||
Docker client and server versions. For this reason, running with this variable
|
||
set is only intended as a workaround and it is not officially supported.</p>
|
||
|
||
<p>If you run into problems running with this set, resolve the mismatch through
|
||
upgrade and remove this setting to see if your problems resolve before notifying
|
||
support.</p>
|
||
|
||
<h2 id="docker-host">DOCKER_HOST</h2>
|
||
|
||
<p>Sets the URL of the <code>docker</code> daemon. As with the Docker client, defaults to <code>unix:///var/run/docker.sock</code>.</p>
|
||
|
||
<h2 id="docker-tls-verify">DOCKER_TLS_VERIFY</h2>
|
||
|
||
<p>When set to anything other than an empty string, enables TLS communication with
|
||
the <code>docker</code> daemon.</p>
|
||
|
||
<h2 id="docker-cert-path">DOCKER_CERT_PATH</h2>
|
||
|
||
<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-http-timeout">COMPOSE_HTTP_TIMEOUT</h2>
|
||
|
||
<p>Configures the time (in seconds) a request to the Docker daemon is allowed to hang before Compose considers
|
||
it failed. Defaults to 60 seconds.</p>
|
||
|
||
<h2 id="related-information">Related Information</h2>
|
||
|
||
<ul>
|
||
<li><a href="../compose/">User guide</a></li>
|
||
<li><a href="../compose/install/">Installing Compose</a></li>
|
||
<li><a href="../compose/compose-file/">Compose file reference</a></li>
|
||
<li><a href="../compose/env-file/">Environment file</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Command-line Completion</title>
|
||
<link>http://docs-stage.docker.com/compose/completion/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/completion/</guid>
|
||
<description>
|
||
|
||
<h1 id="command-line-completion">Command-line 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 --short)/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 --short)/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="../compose/">User guide</a></li>
|
||
<li><a href="../compose/install/">Installing Compose</a></li>
|
||
<li><a href="../compose/django/">Get started with Django</a></li>
|
||
<li><a href="../compose/rails/">Get started with Rails</a></li>
|
||
<li><a href="../compose/wordpress/">Get started with WordPress</a></li>
|
||
<li><a href="../compose/reference/">Command line reference</a></li>
|
||
<li><a href="../compose/compose-file/">Compose file reference</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Command-line Reference</title>
|
||
<link>http://docs-stage.docker.com/compose/reference/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/reference/</guid>
|
||
<description>
|
||
|
||
<h2 id="compose-command-line-reference">Compose command-line reference</h2>
|
||
|
||
<p>The following pages describe the usage information for the <a href="../compose/reference/overview/">docker-compose</a> subcommands. You can also see this information by running <code>docker-compose [SUBCOMMAND] --help</code> from the command line.</p>
|
||
|
||
<ul>
|
||
<li><a href="../compose/reference/overview/">docker-compose</a></li>
|
||
<li><a href="../compose/reference/build/">build</a></li>
|
||
<li><a href="../compose/reference/config/">config</a></li>
|
||
<li><a href="../compose/reference/create/">create</a></li>
|
||
<li><a href="../compose/reference/down/">down</a></li>
|
||
<li><a href="../compose/reference/events/">events</a></li>
|
||
<li><a href="../compose/reference/help/">help</a></li>
|
||
<li><a href="../compose/reference/kill/">kill</a></li>
|
||
<li><a href="../compose/reference/logs/">logs</a></li>
|
||
<li><a href="../compose/reference/pause/">pause</a></li>
|
||
<li><a href="../compose/reference/port/">port</a></li>
|
||
<li><a href="../compose/reference/ps/">ps</a></li>
|
||
<li><a href="../compose/reference/pull/">pull</a></li>
|
||
<li><a href="../compose/reference/restart/">restart</a></li>
|
||
<li><a href="../compose/reference/rm/">rm</a></li>
|
||
<li><a href="../compose/reference/run/">run</a></li>
|
||
<li><a href="../compose/reference/scale/">scale</a></li>
|
||
<li><a href="../compose/reference/start/">start</a></li>
|
||
<li><a href="../compose/reference/stop/">stop</a></li>
|
||
<li><a href="../compose/reference/unpause/">unpause</a></li>
|
||
<li><a href="../compose/reference/up/">up</a></li>
|
||
</ul>
|
||
|
||
<h2 id="where-to-go-next">Where to go next</h2>
|
||
|
||
<ul>
|
||
<li><a href="../compose/reference/envvars/">CLI environment variables</a></li>
|
||
<li><a href="../compose/reference/overview/">docker-compose Command</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Compose File Reference</title>
|
||
<link>http://docs-stage.docker.com/compose/compose-file/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/compose-file/</guid>
|
||
<description>
|
||
|
||
<h1 id="compose-file-reference">Compose file reference</h1>
|
||
|
||
<p>The Compose file is a <a href="http://yaml.org/">YAML</a> file defining
|
||
<a href="#service-configuration-reference">services</a>,
|
||
<a href="#network-configuration-reference">networks</a> and
|
||
<a href="#volume-configuration-reference">volumes</a>.
|
||
The default path for a Compose file is <code>./docker-compose.yml</code>.</p>
|
||
|
||
<p>A service definition contains configuration which will be applied to each
|
||
container started for that service, much like passing command-line parameters to
|
||
<code>docker run</code>. Likewise, network and volume definitions are analogous to
|
||
<code>docker network create</code> and <code>docker volume create</code>.</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>
|
||
|
||
<p>You can use environment variables in configuration values with a Bash-like
|
||
<code>${VARIABLE}</code> syntax - see <a href="#variable-substitution">variable substitution</a> for
|
||
full details.</p>
|
||
|
||
<h2 id="service-configuration-reference">Service configuration reference</h2>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> There are two versions of the Compose file format – version 1 (the
|
||
legacy format, which does not support volumes or networks) and version 2 (the
|
||
most up-to-date). For more information, see the <a href="#versioning">Versioning</a>
|
||
section.</p>
|
||
</blockquote>
|
||
|
||
<p>This section contains a list of all configuration options supported by a service
|
||
definition.</p>
|
||
|
||
<h3 id="build">build</h3>
|
||
|
||
<p>Configuration options that are applied at build time.</p>
|
||
|
||
<p><code>build</code> can be specified either as a string containing a path to the build
|
||
context, or an object with the path specified under <a href="#context">context</a> and
|
||
optionally <a href="#dockerfile">dockerfile</a> and <a href="#args">args</a>.</p>
|
||
|
||
<pre><code>build: ./dir
|
||
|
||
build:
|
||
context: ./dir
|
||
dockerfile: Dockerfile-alternate
|
||
args:
|
||
buildno: 1
|
||
</code></pre>
|
||
|
||
<p>If you specify <code>image</code> as well as <code>build</code>, then Compose names the built image
|
||
with the <code>webapp</code> and optional <code>tag</code> specified in <code>image</code>:</p>
|
||
|
||
<pre><code>build: ./dir
|
||
image: webapp:tag
|
||
</code></pre>
|
||
|
||
<p>This will result in an image named <code>webapp</code> and tagged <code>tag</code>, built from <code>./dir</code>.</p>
|
||
|
||
<blockquote>
|
||
<p><strong>Note</strong>: In the <a href="#version-1">version 1 file format</a>, <code>build</code> is different in
|
||
two ways:</p>
|
||
|
||
<ul>
|
||
<li>Only the string form (<code>build: .</code>) is allowed - not the object form.</li>
|
||
<li>Using <code>build</code> together with <code>image</code> is not allowed. Attempting to do so
|
||
results in an error.</li>
|
||
</ul>
|
||
</blockquote>
|
||
|
||
<h4 id="context">context</h4>
|
||
|
||
<blockquote>
|
||
<p><a href="#version-2">Version 2 file format</a> only. In version 1, just use
|
||
<a href="#build">build</a>.</p>
|
||
</blockquote>
|
||
|
||
<p>Either a path to a directory containing a Dockerfile, or a url to a git repository.</p>
|
||
|
||
<p>When the value supplied is a relative path, it is interpreted as relative to the
|
||
location of the Compose file. 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:
|
||
context: ./dir
|
||
</code></pre>
|
||
|
||
<h4 id="dockerfile">dockerfile</h4>
|
||
|
||
<p>Alternate Dockerfile.</p>
|
||
|
||
<p>Compose will use an alternate file to build with. A build path must also be
|
||
specified.</p>
|
||
|
||
<pre><code>build:
|
||
context: .
|
||
dockerfile: Dockerfile-alternate
|
||
</code></pre>
|
||
|
||
<blockquote>
|
||
<p><strong>Note</strong>: In the <a href="#version-1">version 1 file format</a>, <code>dockerfile</code> is
|
||
different in two ways:</p>
|
||
</blockquote>
|
||
|
||
<ul>
|
||
<li><p>It appears alongside <code>build</code>, not as a sub-option:</p>
|
||
|
||
<pre><code>build: .
|
||
dockerfile: Dockerfile-alternate
|
||
</code></pre></li>
|
||
|
||
<li><p>Using <code>dockerfile</code> together with <code>image</code> is not allowed. Attempting to do so results in an error.</p></li>
|
||
</ul>
|
||
|
||
<h4 id="args">args</h4>
|
||
|
||
<blockquote>
|
||
<p><a href="#version-2">Version 2 file format</a> only.</p>
|
||
</blockquote>
|
||
|
||
<p>Add build arguments. You can use either an array or a dictionary. Any
|
||
boolean values; true, false, yes, no, need to be enclosed in quotes to ensure
|
||
they are not converted to True or False by the YML parser.</p>
|
||
|
||
<p>Build arguments with only a key are resolved to their environment value on the
|
||
machine Compose is running on.</p>
|
||
|
||
<pre><code>build:
|
||
args:
|
||
buildno: 1
|
||
user: someuser
|
||
|
||
build:
|
||
args:
|
||
- buildno=1
|
||
- user=someuser
|
||
</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="command">command</h3>
|
||
|
||
<p>Override the default command.</p>
|
||
|
||
<pre><code>command: bundle exec thin -p 3000
|
||
</code></pre>
|
||
|
||
<p>The command can also be a list, in a manner similar to <a href="https://docs.docker.com/engine/reference/builder/#cmd">dockerfile</a>:</p>
|
||
|
||
<pre><code>command: [bundle, exec, thin, -p, 3000]
|
||
</code></pre>
|
||
|
||
<h3 id="cgroup-parent">cgroup_parent</h3>
|
||
|
||
<p>Specify an optional parent cgroup for the container.</p>
|
||
|
||
<pre><code>cgroup_parent: m-executor-abcd
|
||
</code></pre>
|
||
|
||
<h3 id="container-name">container_name</h3>
|
||
|
||
<p>Specify a custom container name, rather than a generated default name.</p>
|
||
|
||
<pre><code>container_name: my-web-container
|
||
</code></pre>
|
||
|
||
<p>Because Docker container names must be unique, you cannot scale a service
|
||
beyond 1 container if you have specified a custom name. Attempting to do so
|
||
results in an error.</p>
|
||
|
||
<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="depends-on">depends_on</h3>
|
||
|
||
<p>Express dependency between services, which has two effects:</p>
|
||
|
||
<ul>
|
||
<li><p><code>docker-compose up</code> will start services in dependency order. In the following
|
||
example, <code>db</code> and <code>redis</code> will be started before <code>web</code>.</p></li>
|
||
|
||
<li><p><code>docker-compose up SERVICE</code> will automatically include <code>SERVICE</code>&rsquo;s
|
||
dependencies. In the following example, <code>docker-compose up web</code> will also
|
||
create and start <code>db</code> and <code>redis</code>.</p></li>
|
||
</ul>
|
||
|
||
<p>Simple example:</p>
|
||
|
||
<pre><code>version: '2'
|
||
services:
|
||
web:
|
||
build: .
|
||
depends_on:
|
||
- db
|
||
- redis
|
||
redis:
|
||
image: redis
|
||
db:
|
||
image: postgres
|
||
</code></pre>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> <code>depends_on</code> will not wait for <code>db</code> and <code>redis</code> to be &ldquo;ready&rdquo; before
|
||
starting <code>web</code> - only until they have been started. If you need to wait
|
||
for a service to be ready, see <a href="../compose/startup-order/">Controlling startup order</a>
|
||
for more on this problem and strategies for solving it.</p>
|
||
</blockquote>
|
||
|
||
<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="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="tmpfs">tmpfs</h3>
|
||
|
||
<p>Mount a temporary file system inside the container. Can be a single value or a list.</p>
|
||
|
||
<pre><code>tmpfs: /run
|
||
tmpfs:
|
||
- /run
|
||
- /tmp
|
||
</code></pre>
|
||
|
||
<h3 id="entrypoint">entrypoint</h3>
|
||
|
||
<p>Override the default entrypoint.</p>
|
||
|
||
<pre><code>entrypoint: /code/entrypoint.sh
|
||
</code></pre>
|
||
|
||
<p>The entrypoint can also be a list, in a manner similar to <a href="https://docs.docker.com/engine/reference/builder/#entrypoint">dockerfile</a>:</p>
|
||
|
||
<pre><code>entrypoint:
|
||
- php
|
||
- -d
|
||
- zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so
|
||
- -d
|
||
- memory_limit=-1
|
||
- vendor/bin/phpunit
|
||
</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="environment">environment</h3>
|
||
|
||
<p>Add environment variables. You can use either an array or a dictionary. Any
|
||
boolean values; true, false, yes no, need to be enclosed in quotes to ensure
|
||
they are not converted to True or False by the YML parser.</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
|
||
SHOW: 'true'
|
||
SESSION_SECRET:
|
||
|
||
environment:
|
||
- RACK_ENV=development
|
||
- SHOW=true
|
||
- SESSION_SECRET
|
||
</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="extends">extends</h3>
|
||
|
||
<p>Extend another service, in the current file or another, optionally overriding
|
||
configuration.</p>
|
||
|
||
<p>You can use <code>extends</code> on any service together with other configuration keys.
|
||
The <code>extends</code> value must be a dictionary defined with a required <code>service</code>
|
||
and an optional <code>file</code> key.</p>
|
||
|
||
<pre><code>extends:
|
||
file: common.yml
|
||
service: webapp
|
||
</code></pre>
|
||
|
||
<p>The <code>service</code> the name of the service being extended, for example
|
||
<code>web</code> or <code>database</code>. The <code>file</code> is the location of a Compose configuration
|
||
file defining that service.</p>
|
||
|
||
<p>If you omit the <code>file</code> Compose looks for the service configuration in the
|
||
current file. The <code>file</code> value can be an absolute or relative path. If you
|
||
specify a relative path, Compose treats it as relative to the location of the
|
||
current file.</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 one.</p>
|
||
|
||
<p>For more on <code>extends</code>, see the
|
||
<a href="../compose/extends/#extending-services">the extends documentation</a>.</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>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> If you&rsquo;re using the <a href="#version-2">version 2 file format</a>, the
|
||
externally-created containers must be connected to at least one of the same
|
||
networks as the service which is linking to them.</p>
|
||
</blockquote>
|
||
|
||
<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="image">image</h3>
|
||
|
||
<p>Specify the image to start the container from. Can either be a repository/tag or
|
||
a partial image ID.</p>
|
||
|
||
<pre><code>image: redis
|
||
image: ubuntu:14.04
|
||
image: tutum/influxdb
|
||
image: example-registry.com:4000/postgresql
|
||
image: a4bc65fd
|
||
</code></pre>
|
||
|
||
<p>If the image does not exist, Compose attempts to pull it, unless you have also
|
||
specified <a href="#build">build</a>, in which case it builds it using the specified
|
||
options and tags it with the specified tag.</p>
|
||
|
||
<blockquote>
|
||
<p><strong>Note</strong>: In the <a href="#version-1">version 1 file format</a>, using <code>build</code> together
|
||
with <code>image</code> is not allowed. Attempting to do so results in an error.</p>
|
||
</blockquote>
|
||
|
||
<h3 id="labels">labels</h3>
|
||
|
||
<p>Add metadata to containers using <a href="https://docs.docker.com/engine/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="links">links</h3>
|
||
|
||
<p>Link to containers in another service. Either specify both the service name and
|
||
a link alias (<code>SERVICE:ALIAS</code>), or just the service name.</p>
|
||
|
||
<pre><code>web:
|
||
links:
|
||
- db
|
||
- db:database
|
||
- redis
|
||
</code></pre>
|
||
|
||
<p>Containers for the linked service will be reachable at a hostname identical to
|
||
the alias, or the service name if no alias was specified.</p>
|
||
|
||
<p>Links also express dependency between services in the same way as
|
||
<a href="#depends-on">depends_on</a>, so they determine the order of service startup.</p>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> If you define both links and <a href="#networks">networks</a>, services with
|
||
links between them must share at least one network in common in order to
|
||
communicate.</p>
|
||
</blockquote>
|
||
|
||
<h3 id="logging">logging</h3>
|
||
|
||
<blockquote>
|
||
<p><a href="#version-2">Version 2 file format</a> only. In version 1, use
|
||
<a href="#log_driver">log_driver</a> and <a href="#log_opt">log_opt</a>.</p>
|
||
</blockquote>
|
||
|
||
<p>Logging configuration for the service.</p>
|
||
|
||
<pre><code>logging:
|
||
driver: syslog
|
||
options:
|
||
syslog-address: &quot;tcp://192.168.0.42:123&quot;
|
||
</code></pre>
|
||
|
||
<p>The <code>driver</code> name specifies a logging driver for the service&rsquo;s
|
||
containers, as with the <code>--log-driver</code> option for docker run
|
||
(<a href="https://docs.docker.com/engine/reference/logging/overview/">documented here</a>).</p>
|
||
|
||
<p>The default value is json-file.</p>
|
||
|
||
<pre><code>driver: &quot;json-file&quot;
|
||
driver: &quot;syslog&quot;
|
||
driver: &quot;none&quot;
|
||
</code></pre>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> Only the <code>json-file</code> driver makes the logs available directly from
|
||
<code>docker-compose up</code> and <code>docker-compose logs</code>. Using any other driver will not
|
||
print any logs.</p>
|
||
</blockquote>
|
||
|
||
<p>Specify logging options for the logging driver with the <code>options</code> key, as with the <code>--log-opt</code> option for <code>docker run</code>.</p>
|
||
|
||
<p>Logging options are key-value pairs. An example of <code>syslog</code> options:</p>
|
||
|
||
<pre><code>driver: &quot;syslog&quot;
|
||
options:
|
||
syslog-address: &quot;tcp://192.168.0.42:123&quot;
|
||
</code></pre>
|
||
|
||
<h3 id="log-driver">log_driver</h3>
|
||
|
||
<blockquote>
|
||
<p><a href="#version-1">Version 1 file format</a> only. In version 2, use
|
||
<a href="#logging">logging</a>.</p>
|
||
</blockquote>
|
||
|
||
<p>Specify a log driver. The default is <code>json-file</code>.</p>
|
||
|
||
<pre><code>log_driver: syslog
|
||
</code></pre>
|
||
|
||
<h3 id="log-opt">log_opt</h3>
|
||
|
||
<blockquote>
|
||
<p><a href="#version-1">Version 1 file format</a> only. In version 2, use
|
||
<a href="#logging">logging</a>.</p>
|
||
</blockquote>
|
||
|
||
<p>Specify logging options as key-value pairs. An example of <code>syslog</code> options:</p>
|
||
|
||
<pre><code>log_opt:
|
||
syslog-address: &quot;tcp://192.168.0.42:123&quot;
|
||
</code></pre>
|
||
|
||
<h3 id="net">net</h3>
|
||
|
||
<blockquote>
|
||
<p><a href="#version-1">Version 1 file format</a> only. In version 2, use
|
||
<a href="#network_mode">network_mode</a>.</p>
|
||
</blockquote>
|
||
|
||
<p>Network mode. Use the same values as the docker client <code>--net</code> parameter.
|
||
The <code>container:...</code> form can take a service name instead of a container name or
|
||
id.</p>
|
||
|
||
<pre><code>net: &quot;bridge&quot;
|
||
net: &quot;host&quot;
|
||
net: &quot;none&quot;
|
||
net: &quot;container:[service name or container name/id]&quot;
|
||
</code></pre>
|
||
|
||
<h3 id="network-mode">network_mode</h3>
|
||
|
||
<blockquote>
|
||
<p><a href="#version-2">Version 2 file format</a> only. In version 1, use <a href="#net">net</a>.</p>
|
||
</blockquote>
|
||
|
||
<p>Network mode. Use the same values as the docker client <code>--net</code> parameter, plus
|
||
the special form <code>service:[service name]</code>.</p>
|
||
|
||
<pre><code>network_mode: &quot;bridge&quot;
|
||
network_mode: &quot;host&quot;
|
||
network_mode: &quot;none&quot;
|
||
network_mode: &quot;service:[service name]&quot;
|
||
network_mode: &quot;container:[container name/id]&quot;
|
||
</code></pre>
|
||
|
||
<h3 id="networks">networks</h3>
|
||
|
||
<blockquote>
|
||
<p><a href="#version-2">Version 2 file format</a> only. In version 1, use <a href="#net">net</a>.</p>
|
||
</blockquote>
|
||
|
||
<p>Networks to join, referencing entries under the
|
||
<a href="#network-configuration-reference">top-level <code>networks</code> key</a>.</p>
|
||
|
||
<pre><code>services:
|
||
some-service:
|
||
networks:
|
||
- some-network
|
||
- other-network
|
||
</code></pre>
|
||
|
||
<h4 id="aliases">aliases</h4>
|
||
|
||
<p>Aliases (alternative hostnames) for this service on the network. Other containers on the same network can use either the service name or this alias to connect to one of the service&rsquo;s containers.</p>
|
||
|
||
<p>Since <code>aliases</code> is network-scoped, the same service can have different aliases on different networks.</p>
|
||
|
||
<blockquote>
|
||
<p><strong>Note</strong>: A network-wide alias can be shared by multiple containers, and even by multiple services. If it is, then exactly which container the name will resolve to is not guaranteed.</p>
|
||
</blockquote>
|
||
|
||
<p>The general format is shown here.</p>
|
||
|
||
<pre><code>services:
|
||
some-service:
|
||
networks:
|
||
some-network:
|
||
aliases:
|
||
- alias1
|
||
- alias3
|
||
other-network:
|
||
aliases:
|
||
- alias2
|
||
</code></pre>
|
||
|
||
<p>In the example below, three services are provided (<code>web</code>, <code>worker</code>, and <code>db</code>), along with two networks (<code>new</code> and <code>legacy</code>). The <code>db</code> service is reachable at the hostname <code>db</code> or <code>database</code> on the <code>new</code> network, and at <code>db</code> or <code>mysql</code> on the <code>legacy</code> network.</p>
|
||
|
||
<pre><code>version: '2'
|
||
|
||
services:
|
||
web:
|
||
build: ./web
|
||
networks:
|
||
- new
|
||
|
||
worker:
|
||
build: ./worker
|
||
networks:
|
||
- legacy
|
||
|
||
db:
|
||
image: mysql
|
||
networks:
|
||
new:
|
||
aliases:
|
||
- database
|
||
legacy:
|
||
aliases:
|
||
- mysql
|
||
|
||
networks:
|
||
new:
|
||
legacy:
|
||
</code></pre>
|
||
|
||
<h4 id="ipv4-address-ipv6-address">ipv4_address, ipv6_address</h4>
|
||
|
||
<p>Specify a static IP address for containers for this service when joining the network.</p>
|
||
|
||
<p>The corresponding network configuration in the <a href="#network-configuration-reference">top-level networks section</a> must have an <code>ipam</code> block with subnet and gateway configurations covering each static address. If IPv6 addressing is desired, the <code>com.docker.network.enable_ipv6</code> driver option must be set to <code>true</code>.</p>
|
||
|
||
<p>An example:</p>
|
||
|
||
<pre><code>version: '2'
|
||
|
||
services:
|
||
app:
|
||
image: busybox
|
||
command: ifconfig
|
||
networks:
|
||
app_net:
|
||
ipv4_address: 172.16.238.10
|
||
ipv6_address: 2001:3984:3989::10
|
||
|
||
networks:
|
||
app_net:
|
||
driver: bridge
|
||
driver_opts:
|
||
com.docker.network.enable_ipv6: &quot;true&quot;
|
||
ipam:
|
||
driver: default
|
||
config:
|
||
- subnet: 172.16.238.0/24
|
||
gateway: 172.16.238.1
|
||
- subnet: 2001:3984:3989::/64
|
||
gateway: 2001:3984:3989::1
|
||
</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="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;3000-3005&quot;
|
||
- &quot;8000:8000&quot;
|
||
- &quot;9090-9091:8080-8081&quot;
|
||
- &quot;49100:22&quot;
|
||
- &quot;127.0.0.1:8001:8001&quot;
|
||
- &quot;127.0.0.1:5000-5010:5000-5010&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="stop-signal">stop_signal</h3>
|
||
|
||
<p>Sets an alternative signal to stop the container. By default <code>stop</code> uses
|
||
SIGTERM. Setting an alternative signal using <code>stop_signal</code> will cause
|
||
<code>stop</code> to send that signal instead.</p>
|
||
|
||
<pre><code>stop_signal: SIGUSR1
|
||
</code></pre>
|
||
|
||
<h3 id="ulimits">ulimits</h3>
|
||
|
||
<p>Override the default ulimits for a container. You can either specify a single
|
||
limit as an integer or soft/hard limits as a mapping.</p>
|
||
|
||
<pre><code>ulimits:
|
||
nproc: 65535
|
||
nofile:
|
||
soft: 20000
|
||
hard: 40000
|
||
</code></pre>
|
||
|
||
<h3 id="volumes-volume-driver">volumes, volume_driver</h3>
|
||
|
||
<p>Mount paths or named volumes, optionally specifying a path on the host machine
|
||
(<code>HOST:CONTAINER</code>), or an access mode (<code>HOST:CONTAINER:ro</code>).
|
||
For <a href="#version-2">version 2 files</a>, named volumes need to be specified with the
|
||
<a href="#volume-configuration-reference">top-level <code>volumes</code> key</a>.
|
||
When using <a href="#version-1">version 1</a>, the Docker Engine will create the named
|
||
volume automatically if it doesn&rsquo;t exist.</p>
|
||
|
||
<p>You can mount a relative path on the host, which will expand relative to
|
||
the directory of the Compose configuration file being used. Relative paths
|
||
should always begin with <code>.</code> or <code>..</code>.</p>
|
||
|
||
<pre><code>volumes:
|
||
# Just specify a path and let the Engine create a volume
|
||
- /var/lib/mysql
|
||
|
||
# Specify an absolute path mapping
|
||
- /opt/data:/var/lib/mysql
|
||
|
||
# Path on the host, relative to the Compose file
|
||
- ./cache:/tmp/cache
|
||
|
||
# User-relative path
|
||
- ~/configs:/etc/configs/:ro
|
||
|
||
# Named volume
|
||
- datavolume:/var/lib/mysql
|
||
</code></pre>
|
||
|
||
<p>If you do not use a host path, you may specify a <code>volume_driver</code>.</p>
|
||
|
||
<pre><code>volume_driver: mydriver
|
||
</code></pre>
|
||
|
||
<p>Note that for <a href="#version-2">version 2 files</a>, this driver
|
||
will not apply to named volumes (you should use the <code>driver</code> option when
|
||
<a href="#volume-configuration-reference">declaring the volume</a> instead).
|
||
For <a href="#version-1">version 1</a>, both named volumes and container volumes will
|
||
use the specified driver.</p>
|
||
|
||
<blockquote>
|
||
<p>Note: No path expansion will be done if you have also specified a
|
||
<code>volume_driver</code>.</p>
|
||
</blockquote>
|
||
|
||
<p>See <a href="https://docs.docker.com/engine/userguide/dockervolumes/">Docker Volumes</a> and
|
||
<a href="https://docs.docker.com/engine/extend/plugins_volume/">Volume Plugins</a> for more
|
||
information.</p>
|
||
|
||
<h3 id="volumes-from">volumes_from</h3>
|
||
|
||
<p>Mount all of the volumes from another service or container, optionally
|
||
specifying read-only access (<code>ro</code>) or read-write (<code>rw</code>). If no access level is specified,
|
||
then read-write will be used.</p>
|
||
|
||
<pre><code>volumes_from:
|
||
- service_name
|
||
- service_name:ro
|
||
- container:container_name
|
||
- container:container_name:rw
|
||
</code></pre>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> The <code>container:...</code> formats are only supported in the
|
||
<a href="#version-2">version 2 file format</a>. In <a href="#version-1">version 1</a>, you can use
|
||
container names without marking them as such:</p>
|
||
|
||
<pre><code>- service_name
|
||
- service_name:ro
|
||
- container_name
|
||
- container_name:rw
|
||
</code></pre>
|
||
</blockquote>
|
||
|
||
<h3 id="cpu-shares-cpu-quota-cpuset-domainname-hostname-ipc-mac-address-mem-limit-memswap-limit-privileged-read-only-restart-shm-size-stdin-open-tty-user-working-dir">cpu_shares, cpu_quota, cpuset, domainname, hostname, ipc, mac_address, mem_limit, memswap_limit, privileged, read_only, restart, shm_size, stdin_open, tty, user, working_dir</h3>
|
||
|
||
<p>Each of these is a single value, analogous to its
|
||
<a href="https://docs.docker.com/engine/reference/run/">docker run</a> counterpart.</p>
|
||
|
||
<pre><code>cpu_shares: 73
|
||
cpu_quota: 50000
|
||
cpuset: 0,1
|
||
|
||
user: postgresql
|
||
working_dir: /code
|
||
|
||
domainname: foo.com
|
||
hostname: foo
|
||
ipc: host
|
||
mac_address: 02:42:ac:11:65:43
|
||
|
||
mem_limit: 1000000000
|
||
memswap_limit: 2000000000
|
||
privileged: true
|
||
|
||
restart: always
|
||
|
||
read_only: true
|
||
shm_size: 64M
|
||
stdin_open: true
|
||
tty: true
|
||
</code></pre>
|
||
|
||
<h2 id="volume-configuration-reference">Volume configuration reference</h2>
|
||
|
||
<p>While it is possible to declare volumes on the fly as part of the service
|
||
declaration, this section allows you to create named volumes that can be
|
||
reused across multiple services (without relying on <code>volumes_from</code>), and are
|
||
easily retrieved and inspected using the docker command line or API.
|
||
See the <a href="https://docs.docker.com/engine/reference/commandline/volume_create/">docker volume</a>
|
||
subcommand documentation for more information.</p>
|
||
|
||
<h3 id="driver">driver</h3>
|
||
|
||
<p>Specify which volume driver should be used for this volume. Defaults to
|
||
<code>local</code>. The Docker Engine will return an error if the driver is not available.</p>
|
||
|
||
<pre><code> driver: foobar
|
||
</code></pre>
|
||
|
||
<h3 id="driver-opts">driver_opts</h3>
|
||
|
||
<p>Specify a list of options as key-value pairs to pass to the driver for this
|
||
volume. Those options are driver-dependent - consult the driver&rsquo;s
|
||
documentation for more information. Optional.</p>
|
||
|
||
<pre><code> driver_opts:
|
||
foo: &quot;bar&quot;
|
||
baz: 1
|
||
</code></pre>
|
||
|
||
<h3 id="external">external</h3>
|
||
|
||
<p>If set to <code>true</code>, specifies that this volume has been created outside of
|
||
Compose. <code>docker-compose up</code> will not attempt to create it, and will raise
|
||
an error if it doesn&rsquo;t exist.</p>
|
||
|
||
<p><code>external</code> cannot be used in conjunction with other volume configuration keys
|
||
(<code>driver</code>, <code>driver_opts</code>).</p>
|
||
|
||
<p>In the example below, instead of attemping to create a volume called
|
||
<code>[projectname]_data</code>, Compose will look for an existing volume simply
|
||
called <code>data</code> and mount it into the <code>db</code> service&rsquo;s containers.</p>
|
||
|
||
<pre><code>version: '2'
|
||
|
||
services:
|
||
db:
|
||
image: postgres
|
||
volumes:
|
||
- data:/var/lib/postgres/data
|
||
|
||
volumes:
|
||
data:
|
||
external: true
|
||
</code></pre>
|
||
|
||
<p>You can also specify the name of the volume separately from the name used to
|
||
refer to it within the Compose file:</p>
|
||
|
||
<pre><code>volumes
|
||
data:
|
||
external:
|
||
name: actual-name-of-volume
|
||
</code></pre>
|
||
|
||
<h2 id="network-configuration-reference">Network configuration reference</h2>
|
||
|
||
<p>The top-level <code>networks</code> key lets you specify networks to be created. For a full
|
||
explanation of Compose&rsquo;s use of Docker networking features, see the
|
||
<a href="../compose/networking/">Networking guide</a>.</p>
|
||
|
||
<h3 id="driver-1">driver</h3>
|
||
|
||
<p>Specify which driver should be used for this network.</p>
|
||
|
||
<p>The default driver depends on how the Docker Engine you&rsquo;re using is configured,
|
||
but in most instances it will be <code>bridge</code> on a single host and <code>overlay</code> on a
|
||
Swarm.</p>
|
||
|
||
<p>The Docker Engine will return an error if the driver is not available.</p>
|
||
|
||
<pre><code>driver: overlay
|
||
</code></pre>
|
||
|
||
<h3 id="driver-opts-1">driver_opts</h3>
|
||
|
||
<p>Specify a list of options as key-value pairs to pass to the driver for this
|
||
network. Those options are driver-dependent - consult the driver&rsquo;s
|
||
documentation for more information. Optional.</p>
|
||
|
||
<pre><code> driver_opts:
|
||
foo: &quot;bar&quot;
|
||
baz: 1
|
||
</code></pre>
|
||
|
||
<h3 id="ipam">ipam</h3>
|
||
|
||
<p>Specify custom IPAM config. This is an object with several properties, each of
|
||
which is optional:</p>
|
||
|
||
<ul>
|
||
<li><code>driver</code>: Custom IPAM driver, instead of the default.</li>
|
||
<li><code>config</code>: A list with zero or more config blocks, each containing any of
|
||
the following keys:
|
||
|
||
<ul>
|
||
<li><code>subnet</code>: Subnet in CIDR format that represents a network segment</li>
|
||
<li><code>ip_range</code>: Range of IPs from which to allocate container IPs</li>
|
||
<li><code>gateway</code>: IPv4 or IPv6 gateway for the master subnet</li>
|
||
<li><code>aux_addresses</code>: Auxiliary IPv4 or IPv6 addresses used by Network driver,
|
||
as a mapping from hostname to IP</li>
|
||
</ul></li>
|
||
</ul>
|
||
|
||
<p>A full example:</p>
|
||
|
||
<pre><code>ipam:
|
||
driver: default
|
||
config:
|
||
- subnet: 172.28.0.0/16
|
||
ip_range: 172.28.5.0/24
|
||
gateway: 172.28.5.254
|
||
aux_addresses:
|
||
host1: 172.28.1.5
|
||
host2: 172.28.1.6
|
||
host3: 172.28.1.7
|
||
</code></pre>
|
||
|
||
<h3 id="external-1">external</h3>
|
||
|
||
<p>If set to <code>true</code>, specifies that this network has been created outside of
|
||
Compose. <code>docker-compose up</code> will not attempt to create it, and will raise
|
||
an error if it doesn&rsquo;t exist.</p>
|
||
|
||
<p><code>external</code> cannot be used in conjunction with other network configuration keys
|
||
(<code>driver</code>, <code>driver_opts</code>, <code>ipam</code>).</p>
|
||
|
||
<p>In the example below, <code>proxy</code> is the gateway to the outside world. Instead of
|
||
attemping to create a network called <code>[projectname]_outside</code>, Compose will
|
||
look for an existing network simply called <code>outside</code> and connect the <code>proxy</code>
|
||
service&rsquo;s containers to it.</p>
|
||
|
||
<pre><code>version: '2'
|
||
|
||
services:
|
||
proxy:
|
||
build: ./proxy
|
||
networks:
|
||
- outside
|
||
- default
|
||
app:
|
||
build: ./app
|
||
networks:
|
||
- default
|
||
|
||
networks:
|
||
outside:
|
||
external: true
|
||
</code></pre>
|
||
|
||
<p>You can also specify the name of the network separately from the name used to
|
||
refer to it within the Compose file:</p>
|
||
|
||
<pre><code>networks:
|
||
outside:
|
||
external:
|
||
name: actual-name-of-network
|
||
</code></pre>
|
||
|
||
<h2 id="versioning">Versioning</h2>
|
||
|
||
<p>There are two versions of the Compose file format:</p>
|
||
|
||
<ul>
|
||
<li>Version 1, the legacy format. This is specified by omitting a <code>version</code> key at
|
||
the root of the YAML.</li>
|
||
<li>Version 2, the recommended format. This is specified with a <code>version: '2'</code> entry
|
||
at the root of the YAML.</li>
|
||
</ul>
|
||
|
||
<p>To move your project from version 1 to 2, see the <a href="#upgrading">Upgrading</a>
|
||
section.</p>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> If you&rsquo;re using
|
||
<a href="../compose/extends/#different-environments">multiple Compose files</a> or
|
||
<a href="../compose/extends/#extending-services">extending services</a>, each file must be of the
|
||
same version - you cannot mix version 1 and 2 in a single project.</p>
|
||
</blockquote>
|
||
|
||
<p>Several things differ depending on which version you use:</p>
|
||
|
||
<ul>
|
||
<li>The structure and permitted configuration keys</li>
|
||
<li>The minimum Docker Engine version you must be running</li>
|
||
<li>Compose&rsquo;s behaviour with regards to networking</li>
|
||
</ul>
|
||
|
||
<p>These differences are explained below.</p>
|
||
|
||
<h3 id="version-1">Version 1</h3>
|
||
|
||
<p>Compose files that do not declare a version are considered &ldquo;version 1&rdquo;. In
|
||
those files, all the <a href="#service-configuration-reference">services</a> are declared
|
||
at the root of the document.</p>
|
||
|
||
<p>Version 1 is supported by <strong>Compose up to 1.6.x</strong>. It will be deprecated in a
|
||
future Compose release.</p>
|
||
|
||
<p>Version 1 files cannot declare named
|
||
<a href="#volume-configuration-reference">volumes</a>, <a href="../compose/networking/">networks</a> or
|
||
<a href="#args">build arguments</a>.</p>
|
||
|
||
<p>Example:</p>
|
||
|
||
<pre><code>web:
|
||
build: .
|
||
ports:
|
||
- &quot;5000:5000&quot;
|
||
volumes:
|
||
- .:/code
|
||
links:
|
||
- redis
|
||
redis:
|
||
image: redis
|
||
</code></pre>
|
||
|
||
<h3 id="version-2">Version 2</h3>
|
||
|
||
<p>Compose files using the version 2 syntax must indicate the version number at
|
||
the root of the document. All <a href="#service-configuration-reference">services</a>
|
||
must be declared under the <code>services</code> key.</p>
|
||
|
||
<p>Version 2 files are supported by <strong>Compose 1.6.0+</strong> and require a Docker Engine
|
||
of version <strong>1.10.0+</strong>.</p>
|
||
|
||
<p>Named <a href="#volume-configuration-reference">volumes</a> can be declared under the
|
||
<code>volumes</code> key, and <a href="#network-configuration-reference">networks</a> can be declared
|
||
under the <code>networks</code> key.</p>
|
||
|
||
<p>Simple example:</p>
|
||
|
||
<pre><code>version: '2'
|
||
services:
|
||
web:
|
||
build: .
|
||
ports:
|
||
- &quot;5000:5000&quot;
|
||
volumes:
|
||
- .:/code
|
||
redis:
|
||
image: redis
|
||
</code></pre>
|
||
|
||
<p>A more extended example, defining volumes and networks:</p>
|
||
|
||
<pre><code>version: '2'
|
||
services:
|
||
web:
|
||
build: .
|
||
ports:
|
||
- &quot;5000:5000&quot;
|
||
volumes:
|
||
- .:/code
|
||
networks:
|
||
- front-tier
|
||
- back-tier
|
||
redis:
|
||
image: redis
|
||
volumes:
|
||
- redis-data:/var/lib/redis
|
||
networks:
|
||
- back-tier
|
||
volumes:
|
||
redis-data:
|
||
driver: local
|
||
networks:
|
||
front-tier:
|
||
driver: bridge
|
||
back-tier:
|
||
driver: bridge
|
||
</code></pre>
|
||
|
||
<h3 id="upgrading">Upgrading</h3>
|
||
|
||
<p>In the majority of cases, moving from version 1 to 2 is a very simple process:</p>
|
||
|
||
<ol>
|
||
<li>Indent the whole file by one level and put a <code>services:</code> key at the top.</li>
|
||
<li>Add a <code>version: '2'</code> line at the top of the file.</li>
|
||
</ol>
|
||
|
||
<p>It&rsquo;s more complicated if you&rsquo;re using particular configuration features:</p>
|
||
|
||
<ul>
|
||
<li><p><code>dockerfile</code>: This now lives under the <code>build</code> key:</p>
|
||
|
||
<pre><code>build:
|
||
context: .
|
||
dockerfile: Dockerfile-alternate
|
||
</code></pre></li>
|
||
|
||
<li><p><code>log_driver</code>, <code>log_opt</code>: These now live under the <code>logging</code> key:</p>
|
||
|
||
<pre><code>logging:
|
||
driver: syslog
|
||
options:
|
||
syslog-address: &quot;tcp://192.168.0.42:123&quot;
|
||
</code></pre></li>
|
||
|
||
<li><p><code>links</code> with environment variables: As documented in the
|
||
<a href="../compose/link-env-deprecated/">environment variables reference</a>, environment variables
|
||
created by
|
||
links have been deprecated for some time. In the new Docker network system,
|
||
they have been removed. You should either connect directly to the
|
||
appropriate hostname or set the relevant environment variable yourself,
|
||
using the link hostname:</p>
|
||
|
||
<pre><code>web:
|
||
links:
|
||
- db
|
||
environment:
|
||
- DB_PORT=tcp://db:5432
|
||
</code></pre></li>
|
||
|
||
<li><p><code>external_links</code>: Compose uses Docker networks when running version 2
|
||
projects, so links behave slightly differently. In particular, two
|
||
containers must be connected to at least one network in common in order to
|
||
communicate, even if explicitly linked together.</p>
|
||
|
||
<p>Either connect the external container to your app&rsquo;s
|
||
<a href="../compose/networking/">default network</a>, or connect both the external container and
|
||
your service&rsquo;s containers to an
|
||
<a href="../compose/networking/#using-a-pre-existing-network">external network</a>.</p></li>
|
||
|
||
<li><p><code>net</code>: This is now replaced by <a href="#network_mode">network_mode</a>:</p>
|
||
|
||
<pre><code>net: host -&gt; network_mode: host
|
||
net: bridge -&gt; network_mode: bridge
|
||
net: none -&gt; network_mode: none
|
||
</code></pre>
|
||
|
||
<p>If you&rsquo;re using <code>net: &quot;container:[service name]&quot;</code>, you must now use
|
||
<code>network_mode: &quot;service:[service name]&quot;</code> instead.</p>
|
||
|
||
<pre><code>net: &quot;container:web&quot; -&gt; network_mode: &quot;service:web&quot;
|
||
</code></pre>
|
||
|
||
<p>If you&rsquo;re using <code>net: &quot;container:[container name/id]&quot;</code>, the value does not
|
||
need to change.</p>
|
||
|
||
<pre><code>net: &quot;container:cont-name&quot; -&gt; network_mode: &quot;container:cont-name&quot;
|
||
net: &quot;container:abc12345&quot; -&gt; network_mode: &quot;container:abc12345&quot;
|
||
</code></pre></li>
|
||
|
||
<li><p><code>volumes</code> with named volumes: these must now be explicitly declared in a
|
||
top-level <code>volumes</code> section of your Compose file. If a service mounts a
|
||
named volume called <code>data</code>, you must declare a <code>data</code> volume in your
|
||
top-level <code>volumes</code> section. The whole file might look like this:</p>
|
||
|
||
<pre><code>version: '2'
|
||
services:
|
||
db:
|
||
image: postgres
|
||
volumes:
|
||
- data:/var/lib/postgresql/data
|
||
volumes:
|
||
data: {}
|
||
</code></pre>
|
||
|
||
<p>By default, Compose creates a volume whose name is prefixed with your
|
||
project name. If you want it to just be called <code>data</code>, declare it as
|
||
external:</p>
|
||
|
||
<pre><code>volumes:
|
||
data:
|
||
external: true
|
||
</code></pre></li>
|
||
</ul>
|
||
|
||
<h2 id="variable-substitution">Variable substitution</h2>
|
||
|
||
<p>Your configuration options can contain environment variables. Compose uses the
|
||
variable values from the shell environment in which <code>docker-compose</code> is run.
|
||
For example, suppose the shell contains <code>EXTERNAL_PORT=8000</code> and you supply
|
||
this configuration:</p>
|
||
|
||
<pre><code>web:
|
||
build: .
|
||
ports:
|
||
- &quot;${EXTERNAL_PORT}:5000&quot;
|
||
</code></pre>
|
||
|
||
<p>When you run <code>docker-compose up</code> with this configuration, Compose looks for
|
||
the <code>EXTERNAL_PORT</code> environment variable in the shell and substitutes its
|
||
value in. In this example, Compose resolves the port mapping to <code>&quot;8000:5000&quot;</code>
|
||
before creating the <code>web</code> container.</p>
|
||
|
||
<p>If an environment variable is not set, Compose substitutes with an empty
|
||
string. In the example above, if <code>EXTERNAL_PORT</code> is not set, the value for the
|
||
port mapping is <code>:5000</code> (which is of course an invalid port mapping, and will
|
||
result in an error when attempting to create the container).</p>
|
||
|
||
<p>Both <code>$VARIABLE</code> and <code>${VARIABLE}</code> syntax are supported. Extended shell-style
|
||
features, such as <code>${VARIABLE-default}</code> and <code>${VARIABLE/foo/bar}</code>, are not
|
||
supported.</p>
|
||
|
||
<p>You can use a <code>$$</code> (double-dollar sign) when your configuration needs a literal
|
||
dollar sign. This also prevents Compose from interpolating a value, so a <code>$$</code>
|
||
allows you to refer to environment variables that you don&rsquo;t want processed by
|
||
Compose.</p>
|
||
|
||
<pre><code>web:
|
||
build: .
|
||
command: &quot;$$VAR_NOT_INTERPOLATED_BY_COMPOSE&quot;
|
||
</code></pre>
|
||
|
||
<p>If you forget and use a single dollar sign (<code>$</code>), Compose interprets the value as an environment variable and will warn you:</p>
|
||
|
||
<p>The VAR_NOT_INTERPOLATED_BY_COMPOSE is not set. Substituting an empty string.</p>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="../compose/">User guide</a></li>
|
||
<li><a href="../compose/install/">Installing Compose</a></li>
|
||
<li><a href="../compose/django/">Get started with Django</a></li>
|
||
<li><a href="../compose/rails/">Get started with Rails</a></li>
|
||
<li><a href="../compose/wordpress/">Get started with WordPress</a></li>
|
||
<li><a href="../compose/reference/">Command line reference</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Controlling startup order</title>
|
||
<link>http://docs-stage.docker.com/compose/startup-order/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/startup-order/</guid>
|
||
<description>
|
||
|
||
<h1 id="controlling-startup-order-in-compose">Controlling startup order in Compose</h1>
|
||
|
||
<p>You can control the order of service startup with the
|
||
<a href="../compose/compose-file/#depends-on">depends_on</a> option. Compose always starts
|
||
containers in dependency order, where dependencies are determined by
|
||
<code>depends_on</code>, <code>links</code>, <code>volumes_from</code> and <code>network_mode: &quot;service:...&quot;</code>.</p>
|
||
|
||
<p>However, Compose will not wait until a container is &ldquo;ready&rdquo; (whatever that means
|
||
for your particular application) - only until it&rsquo;s running. There&rsquo;s a good
|
||
reason for this.</p>
|
||
|
||
<p>The problem of waiting for a database (for example) to be ready is really just
|
||
a subset of a much larger problem of distributed systems. In production, your
|
||
database could become unavailable or move hosts at any time. Your application
|
||
needs to be resilient to these types of failures.</p>
|
||
|
||
<p>To handle this, your application should attempt to re-establish a connection to
|
||
the database after a failure. If the application retries the connection,
|
||
it should eventually be able to connect to the database.</p>
|
||
|
||
<p>The best solution is to perform this check in your application code, both at
|
||
startup and whenever a connection is lost for any reason. However, if you don&rsquo;t
|
||
need this level of resilience, you can work around the problem with a wrapper
|
||
script:</p>
|
||
|
||
<ul>
|
||
<li><p>Use a tool such as <a href="https://github.com/vishnubob/wait-for-it">wait-for-it</a>
|
||
or <a href="https://github.com/jwilder/dockerize">dockerize</a>. These are small
|
||
wrapper scripts which you can include in your application&rsquo;s image and will
|
||
poll a given host and port until it&rsquo;s accepting TCP connections.</p>
|
||
|
||
<p>Supposing your application&rsquo;s image has a <code>CMD</code> set in its Dockerfile, you
|
||
can wrap it by setting the entrypoint in <code>docker-compose.yml</code>:</p>
|
||
|
||
<pre><code>version: &quot;2&quot;
|
||
services:
|
||
web:
|
||
build: .
|
||
ports:
|
||
- &quot;80:8000&quot;
|
||
depends_on:
|
||
- &quot;db&quot;
|
||
entrypoint: ./wait-for-it.sh db:5432
|
||
db:
|
||
image: postgres
|
||
</code></pre></li>
|
||
|
||
<li><p>Write your own wrapper script to perform a more application-specific health
|
||
check. For example, you might want to wait until Postgres is definitely
|
||
ready to accept commands:</p>
|
||
|
||
<pre><code>#!/bin/bash
|
||
|
||
set -e
|
||
|
||
host=&quot;$1&quot;
|
||
shift
|
||
cmd=&quot;$@&quot;
|
||
|
||
until psql -h &quot;$host&quot; -U &quot;postgres&quot; -c '\l'; do
|
||
&gt;&amp;2 echo &quot;Postgres is unavailable - sleeping&quot;
|
||
sleep 1
|
||
done
|
||
|
||
&gt;&amp;2 echo &quot;Postgres is up - executing command&quot;
|
||
exec $cmd
|
||
</code></pre>
|
||
|
||
<p>You can use this as a wrapper script as in the previous example, by setting
|
||
<code>entrypoint: ./wait-for-postgres.sh db</code>.</p></li>
|
||
</ul>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="../compose/install/">Installing Compose</a></li>
|
||
<li><a href="../compose/django/">Get started with Django</a></li>
|
||
<li><a href="../compose/rails/">Get started with Rails</a></li>
|
||
<li><a href="../compose/wordpress/">Get started with WordPress</a></li>
|
||
<li><a href="../compose/reference/">Command line reference</a></li>
|
||
<li><a href="../compose/compose-file/">Compose file reference</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Docker Compose</title>
|
||
<link>http://docs-stage.docker.com/compose/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/</guid>
|
||
<description>
|
||
|
||
<h1 id="docker-compose">Docker Compose</h1>
|
||
|
||
<p>Compose is a tool for defining and running multi-container Docker applications. To learn more about Compose refer to the following documentation:</p>
|
||
|
||
<ul>
|
||
<li><a href="../compose/overview/">Compose Overview</a></li>
|
||
<li><a href="../compose/install/">Install Compose</a></li>
|
||
<li><a href="../compose/gettingstarted/">Getting Started</a></li>
|
||
<li><a href="../compose/django/">Get started with Django</a></li>
|
||
<li><a href="../compose/rails/">Get started with Rails</a></li>
|
||
<li><a href="../compose/wordpress/">Get started with WordPress</a></li>
|
||
<li><a href="../compose/faq/">Frequently asked questions</a></li>
|
||
<li><a href="../compose/reference/">Command line reference</a></li>
|
||
<li><a href="../compose/compose-file/">Compose file reference</a></li>
|
||
<li><a href="../compose/env-file/">Environment file</a></li>
|
||
</ul>
|
||
|
||
<p>To see a detailed list of changes for past and current releases of Docker
|
||
Compose, please refer to the
|
||
<a href="https://github.com/docker/compose/blob/master/CHANGELOG.md">CHANGELOG</a>.</p>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Environment file</title>
|
||
<link>http://docs-stage.docker.com/compose/env-file/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/env-file/</guid>
|
||
<description>
|
||
|
||
<h1 id="environment-file">Environment file</h1>
|
||
|
||
<p>Compose supports declaring default environment variables in an environment
|
||
file named <code>.env</code> placed in the folder <code>docker-compose</code> command is executed from
|
||
<em>(current working directory)</em>.</p>
|
||
|
||
<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>
|
||
|
||
<blockquote>
|
||
<p>Note: Values present in the environment at runtime will always override
|
||
those defined inside the <code>.env</code> file. Similarly, values passed via
|
||
command-line arguments take precedence as well.</p>
|
||
</blockquote>
|
||
|
||
<p>Those environment variables will be used for
|
||
<a href="../compose/compose-file/#variable-substitution">variable substitution</a> in your Compose
|
||
file, but can also be used to define the following
|
||
<a href="../compose/reference/envvars/">CLI variables</a>:</p>
|
||
|
||
<ul>
|
||
<li><code>COMPOSE_API_VERSION</code></li>
|
||
<li><code>COMPOSE_FILE</code></li>
|
||
<li><code>COMPOSE_HTTP_TIMEOUT</code></li>
|
||
<li><code>COMPOSE_PROJECT_NAME</code></li>
|
||
<li><code>DOCKER_CERT_PATH</code></li>
|
||
<li><code>DOCKER_HOST</code></li>
|
||
<li><code>DOCKER_TLS_VERIFY</code></li>
|
||
</ul>
|
||
|
||
<h2 id="more-compose-documentation">More Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="../compose/">User guide</a></li>
|
||
<li><a href="../compose/reference/">Command line reference</a></li>
|
||
<li><a href="../compose/compose-file/">Compose file reference</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Extending Services in Compose</title>
|
||
<link>http://docs-stage.docker.com/compose/extends/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/extends/</guid>
|
||
<description>
|
||
|
||
<h1 id="extending-services-and-compose-files">Extending services and Compose files</h1>
|
||
|
||
<p>Compose supports two methods of sharing common configuration:</p>
|
||
|
||
<ol>
|
||
<li>Extending an entire Compose file by
|
||
<a href="#multiple-compose-files">using multiple Compose files</a></li>
|
||
<li>Extending individual services with <a href="#extending-services">the <code>extends</code> field</a></li>
|
||
</ol>
|
||
|
||
<h2 id="multiple-compose-files">Multiple Compose files</h2>
|
||
|
||
<p>Using multiple Compose files enables you to customize a Compose application
|
||
for different environments or different workflows.</p>
|
||
|
||
<h3 id="understanding-multiple-compose-files">Understanding multiple Compose files</h3>
|
||
|
||
<p>By default, Compose reads two files, a <code>docker-compose.yml</code> and an optional
|
||
<code>docker-compose.override.yml</code> file. By convention, the <code>docker-compose.yml</code>
|
||
contains your base configuration. The override file, as its name implies, can
|
||
contain configuration overrides for existing services or entirely new
|
||
services.</p>
|
||
|
||
<p>If a service is defined in both files Compose merges the configurations using
|
||
the rules described in <a href="#adding-and-overriding-configuration">Adding and overriding
|
||
configuration</a>.</p>
|
||
|
||
<p>To use multiple override files, or an override file with a different name, you
|
||
can use the <code>-f</code> option to specify the list of files. Compose merges files in
|
||
the order they&rsquo;re specified on the command line. See the <a href="../compose/reference/overview/"><code>docker-compose</code>
|
||
command reference</a> for more information about
|
||
using <code>-f</code>.</p>
|
||
|
||
<p>When you use multiple configuration files, you must make sure all paths in the
|
||
files are relative to the base Compose file (the first Compose file specified
|
||
with <code>-f</code>). This is required because override files need not be valid
|
||
Compose files. Override files can contain small fragments of configuration.
|
||
Tracking which fragment of a service is relative to which path is difficult and
|
||
confusing, so to keep paths easier to understand, all paths must be defined
|
||
relative to the base file.</p>
|
||
|
||
<h3 id="example-use-case">Example use case</h3>
|
||
|
||
<p>In this section are two common use cases for multiple compose files: changing a
|
||
Compose app for different environments, and running administrative tasks
|
||
against a Compose app.</p>
|
||
|
||
<h4 id="different-environments">Different environments</h4>
|
||
|
||
<p>A common use case for multiple files is changing a development Compose app
|
||
for a production-like environment (which may be production, staging or CI).
|
||
To support these differences, you can split your Compose configuration into
|
||
a few different files:</p>
|
||
|
||
<p>Start with a base file that defines the canonical configuration for the
|
||
services.</p>
|
||
|
||
<p><strong>docker-compose.yml</strong></p>
|
||
|
||
<pre><code>web:
|
||
image: example/my_web_app:latest
|
||
links:
|
||
- db
|
||
- cache
|
||
|
||
db:
|
||
image: postgres:latest
|
||
|
||
cache:
|
||
image: redis:latest
|
||
</code></pre>
|
||
|
||
<p>In this example the development configuration exposes some ports to the
|
||
host, mounts our code as a volume, and builds the web image.</p>
|
||
|
||
<p><strong>docker-compose.override.yml</strong></p>
|
||
|
||
<pre><code>web:
|
||
build: .
|
||
volumes:
|
||
- '.:/code'
|
||
ports:
|
||
- 8883:80
|
||
environment:
|
||
DEBUG: 'true'
|
||
|
||
db:
|
||
command: '-d'
|
||
ports:
|
||
- 5432:5432
|
||
|
||
cache:
|
||
ports:
|
||
- 6379:6379
|
||
</code></pre>
|
||
|
||
<p>When you run <code>docker-compose up</code> it reads the overrides automatically.</p>
|
||
|
||
<p>Now, it would be nice to use this Compose app in a production environment. So,
|
||
create another override file (which might be stored in a different git
|
||
repo or managed by a different team).</p>
|
||
|
||
<p><strong>docker-compose.prod.yml</strong></p>
|
||
|
||
<pre><code>web:
|
||
ports:
|
||
- 80:80
|
||
environment:
|
||
PRODUCTION: 'true'
|
||
|
||
cache:
|
||
environment:
|
||
TTL: '500'
|
||
</code></pre>
|
||
|
||
<p>To deploy with this production Compose file you can run</p>
|
||
|
||
<pre><code>docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
||
</code></pre>
|
||
|
||
<p>This deploys all three services using the configuration in
|
||
<code>docker-compose.yml</code> and <code>docker-compose.prod.yml</code> (but not the
|
||
dev configuration in <code>docker-compose.override.yml</code>).</p>
|
||
|
||
<p>See <a href="../compose/production/">production</a> for more information about Compose in
|
||
production.</p>
|
||
|
||
<h4 id="administrative-tasks">Administrative tasks</h4>
|
||
|
||
<p>Another common use case is running adhoc or administrative tasks against one
|
||
or more services in a Compose app. This example demonstrates running a
|
||
database backup.</p>
|
||
|
||
<p>Start with a <strong>docker-compose.yml</strong>.</p>
|
||
|
||
<pre><code>web:
|
||
image: example/my_web_app:latest
|
||
links:
|
||
- db
|
||
|
||
db:
|
||
image: postgres:latest
|
||
</code></pre>
|
||
|
||
<p>In a <strong>docker-compose.admin.yml</strong> add a new service to run the database
|
||
export or backup.</p>
|
||
|
||
<pre><code>dbadmin:
|
||
build: database_admin/
|
||
links:
|
||
- db
|
||
</code></pre>
|
||
|
||
<p>To start a normal environment run <code>docker-compose up -d</code>. To run a database
|
||
backup, include the <code>docker-compose.admin.yml</code> as well.</p>
|
||
|
||
<pre><code>docker-compose -f docker-compose.yml -f docker-compose.admin.yml \
|
||
run dbadmin db-backup
|
||
</code></pre>
|
||
|
||
<h2 id="extending-services">Extending services</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 services that reuse a common set of configuration
|
||
options. Using <code>extends</code> you can define a common set of service options in one
|
||
place and refer to it from anywhere.</p>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> <code>links</code>, <code>volumes_from</code>, and <code>depends_on</code> are never shared between
|
||
services using &gt;<code>extends</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>
|
||
</blockquote>
|
||
|
||
<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 the same <code>build</code>, <code>ports</code> and <code>volumes</code> configuration
|
||
values 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
|
||
|
||
important_web:
|
||
extends: web
|
||
cpu_shares: 10
|
||
</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>
|
||
|
||
<h3 id="example-use-case-1">Example use case</h3>
|
||
|
||
<p>Extending an individual service is useful when you have multiple services that
|
||
have a common configuration. The example below is a Compose app with
|
||
two services: a web application and a queue worker. Both services use the same
|
||
codebase and share many configuration options.</p>
|
||
|
||
<p>In a <strong>common.yml</strong> we define the common configuration:</p>
|
||
|
||
<pre><code>app:
|
||
build: .
|
||
environment:
|
||
CONFIG_FILE_PATH: /code/config
|
||
API_KEY: xxxyyy
|
||
cpu_shares: 5
|
||
</code></pre>
|
||
|
||
<p>In a <strong>docker-compose.yml</strong> we define the concrete services which use the
|
||
common configuration:</p>
|
||
|
||
<pre><code>webapp:
|
||
extends:
|
||
file: common.yml
|
||
service: app
|
||
command: /code/run_web_app
|
||
ports:
|
||
- 8080:8080
|
||
links:
|
||
- queue
|
||
- db
|
||
|
||
queue_worker:
|
||
extends:
|
||
file: common.yml
|
||
service: app
|
||
command: /code/run_worker
|
||
links:
|
||
- queue
|
||
</code></pre>
|
||
|
||
<h2 id="adding-and-overriding-configuration">Adding and overriding configuration</h2>
|
||
|
||
<p>Compose copies configurations from the original service over to the local one.
|
||
If a configuration option is defined in both the original service the local
|
||
service, the local value <em>replaces</em> or <em>extends</em> the original value.</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.</p>
|
||
|
||
<pre><code># original service
|
||
command: python app.py
|
||
|
||
# local service
|
||
command: python otherapp.py
|
||
|
||
# result
|
||
command: python otherapp.py
|
||
</code></pre>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> In the case of <code>build</code> and <code>image</code>, when using
|
||
<a href="../compose/compose-file/#version-1">version 1 of the Compose file format</a>, using one
|
||
option in the local service causes Compose to discard the other option if it
|
||
was defined in the original service.</p>
|
||
|
||
<p>For example, if the original service defines <code>image: webapp</code> and the
|
||
local service defines <code>build: .</code> then the resulting service will have
|
||
<code>build: .</code> and no <code>image</code> option.</p>
|
||
|
||
<p>This is because <code>build</code> and <code>image</code> cannot be used together in a version 1
|
||
file.</p>
|
||
</blockquote>
|
||
|
||
<p>For the <strong>multi-value options</strong> <code>ports</code>, <code>expose</code>, <code>external_links</code>, <code>dns</code>,
|
||
<code>dns_search</code>, and <code>tmpfs</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>, <code>labels</code>, <code>volumes</code> and <code>devices</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>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="../compose/">User guide</a></li>
|
||
<li><a href="../compose/install/">Installing Compose</a></li>
|
||
<li><a href="../compose/gettingstarted/">Getting Started</a></li>
|
||
<li><a href="../compose/django/">Get started with Django</a></li>
|
||
<li><a href="../compose/rails/">Get started with Rails</a></li>
|
||
<li><a href="../compose/wordpress/">Get started with WordPress</a></li>
|
||
<li><a href="../compose/reference/">Command line reference</a></li>
|
||
<li><a href="../compose/compose-file/">Compose file reference</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Frequently Asked Questions</title>
|
||
<link>http://docs-stage.docker.com/compose/faq/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/faq/</guid>
|
||
<description>
|
||
|
||
<h1 id="frequently-asked-questions">Frequently asked questions</h1>
|
||
|
||
<p>If you don’t see your question here, feel free to drop by <code>#docker-compose</code> on
|
||
freenode IRC and ask the community.</p>
|
||
|
||
<h2 id="can-i-control-service-startup-order">Can I control service startup order?</h2>
|
||
|
||
<p>Yes - see <a href="../compose/startup-order/">Controlling startup order</a>.</p>
|
||
|
||
<h2 id="why-do-my-services-take-10-seconds-to-recreate-or-stop">Why do my services take 10 seconds to recreate or stop?</h2>
|
||
|
||
<p>Compose stop attempts to stop a container by sending a <code>SIGTERM</code>. It then waits
|
||
for a <a href="../compose/reference/stop/">default timeout of 10 seconds</a>. After the timeout,
|
||
a <code>SIGKILL</code> is sent to the container to forcefully kill it. If you
|
||
are waiting for this timeout, it means that your containers aren&rsquo;t shutting down
|
||
when they receive the <code>SIGTERM</code> signal.</p>
|
||
|
||
<p>There has already been a lot written about this problem of
|
||
<a href="https://medium.com/@gchudnov/trapping-signals-in-docker-containers-7a57fdda7d86">processes handling signals</a>
|
||
in containers.</p>
|
||
|
||
<p>To fix this problem, try the following:</p>
|
||
|
||
<ul>
|
||
<li>Make sure you&rsquo;re using the JSON form of <code>CMD</code> and <code>ENTRYPOINT</code>
|
||
in your Dockerfile.</li>
|
||
</ul>
|
||
|
||
<p>For example use <code>[&quot;program&quot;, &quot;arg1&quot;, &quot;arg2&quot;]</code> not <code>&quot;program arg1 arg2&quot;</code>.
|
||
Using the string form causes Docker to run your process using <code>bash</code> which
|
||
doesn&rsquo;t handle signals properly. Compose always uses the JSON form, so don&rsquo;t
|
||
worry if you override the command or entrypoint in your Compose file.</p>
|
||
|
||
<ul>
|
||
<li><p>If you are able, modify the application that you&rsquo;re running to
|
||
add an explicit signal handler for <code>SIGTERM</code>.</p></li>
|
||
|
||
<li><p>Set the <code>stop_signal</code> to a signal which the application knows how to handle:</p>
|
||
|
||
<p>web:
|
||
build: .
|
||
stop_signal: SIGINT</p></li>
|
||
|
||
<li><p>If you can&rsquo;t modify the application, wrap the application in a lightweight init
|
||
system (like <a href="http://skarnet.org/software/s6/">s6</a>) or a signal proxy (like
|
||
<a href="https://github.com/Yelp/dumb-init">dumb-init</a> or
|
||
<a href="https://github.com/krallin/tini">tini</a>). Either of these wrappers take care of
|
||
handling <code>SIGTERM</code> properly.</p></li>
|
||
</ul>
|
||
|
||
<h2 id="how-do-i-run-multiple-copies-of-a-compose-file-on-the-same-host">How do I run multiple copies of a Compose file on the same host?</h2>
|
||
|
||
<p>Compose uses the project name to create unique identifiers for all of a
|
||
project&rsquo;s containers and other resources. To run multiple copies of a project,
|
||
set a custom project name using the <a href="../compose/reference/overview/"><code>-p</code> command line
|
||
option</a> or the <a href="../compose/reference/envvars/#compose-project-name"><code>COMPOSE_PROJECT_NAME</code>
|
||
environment variable</a>.</p>
|
||
|
||
<h2 id="what-s-the-difference-between-up-run-and-start">What&rsquo;s the difference between <code>up</code>, <code>run</code>, and <code>start</code>?</h2>
|
||
|
||
<p>Typically, you want <code>docker-compose up</code>. Use <code>up</code> to start or restart all the
|
||
services defined in a <code>docker-compose.yml</code>. In the default &ldquo;attached&rdquo;
|
||
mode, you&rsquo;ll see all the logs from all the containers. In &ldquo;detached&rdquo; mode (<code>-d</code>),
|
||
Compose exits after starting the containers, but the containers continue to run
|
||
in the background.</p>
|
||
|
||
<p>The <code>docker-compose run</code> command is for running &ldquo;one-off&rdquo; or &ldquo;adhoc&rdquo; tasks. It
|
||
requires the service name you want to run and only starts containers for services
|
||
that the running service depends on. Use <code>run</code> to run tests or perform
|
||
an administrative task such as removing or adding data to a data volume
|
||
container. The <code>run</code> command acts like <code>docker run -ti</code> in that it opens an
|
||
interactive terminal to the container and returns an exit status matching the
|
||
exit status of the process in the container.</p>
|
||
|
||
<p>The <code>docker-compose start</code> command is useful only to restart containers
|
||
that were previously created, but were stopped. It never creates new
|
||
containers.</p>
|
||
|
||
<h2 id="can-i-use-json-instead-of-yaml-for-my-compose-file">Can I use json instead of yaml for my Compose file?</h2>
|
||
|
||
<p>Yes. <a href="http://stackoverflow.com/a/1729545/444646">Yaml is a superset of json</a> so
|
||
any JSON file should be valid Yaml. To use a JSON file with Compose,
|
||
specify the filename to use, for example:</p>
|
||
|
||
<pre><code class="language-bash">docker-compose -f docker-compose.json up
|
||
</code></pre>
|
||
|
||
<h2 id="should-i-include-my-code-with-copy-add-or-a-volume">Should I include my code with <code>COPY</code>/<code>ADD</code> or a volume?</h2>
|
||
|
||
<p>You can add your code to the image using <code>COPY</code> or <code>ADD</code> directive in a
|
||
<code>Dockerfile</code>. This is useful if you need to relocate your code along with the
|
||
Docker image, for example when you&rsquo;re sending code to another environment
|
||
(production, CI, etc).</p>
|
||
|
||
<p>You should use a <code>volume</code> if you want to make changes to your code and see them
|
||
reflected immediately, for example when you&rsquo;re developing code and your server
|
||
supports hot code reloading or live-reload.</p>
|
||
|
||
<p>There may be cases where you&rsquo;ll want to use both. You can have the image
|
||
include the code using a <code>COPY</code>, and use a <code>volume</code> in your Compose file to
|
||
include the code from the host during development. The volume overrides
|
||
the directory contents of the image.</p>
|
||
|
||
<h2 id="where-can-i-find-example-compose-files">Where can I find example compose files?</h2>
|
||
|
||
<p>There are <a href="https://github.com/search?q=in%3Apath+docker-compose.yml+extension%3Ayml&amp;type=Code">many examples of Compose files on
|
||
github</a>.</p>
|
||
|
||
<h2 id="compose-documentation">Compose documentation</h2>
|
||
|
||
<ul>
|
||
<li><a href="../compose/install/">Installing Compose</a></li>
|
||
<li><a href="../compose/django/">Get started with Django</a></li>
|
||
<li><a href="../compose/rails/">Get started with Rails</a></li>
|
||
<li><a href="../compose/wordpress/">Get started with WordPress</a></li>
|
||
<li><a href="../compose/reference/">Command line reference</a></li>
|
||
<li><a href="../compose/compose-file/">Compose file reference</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Getting Started</title>
|
||
<link>http://docs-stage.docker.com/compose/gettingstarted/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/gettingstarted/</guid>
|
||
<description>
|
||
|
||
<h1 id="getting-started">Getting Started</h1>
|
||
|
||
<p>On this page you build a simple Python web application running on Docker Compose. The
|
||
application uses the Flask framework and increments a value in Redis. While the
|
||
sample uses Python, the concepts demonstrated here should be understandable even
|
||
if you&rsquo;re not familiar with it.</p>
|
||
|
||
<h2 id="prerequisites">Prerequisites</h2>
|
||
|
||
<p>Make sure you have already
|
||
<a href="../compose/install/">installed both Docker Engine and Docker Compose</a>. You
|
||
don&rsquo;t need to install Python, it is provided by a Docker image.</p>
|
||
|
||
<h2 id="step-1-setup">Step 1: Setup</h2>
|
||
|
||
<ol>
|
||
<li><p>Create a directory for the project:</p>
|
||
|
||
<pre><code>$ mkdir composetest
|
||
$ cd composetest
|
||
</code></pre></li>
|
||
|
||
<li><p>With your favorite text editor create a file called <code>app.py</code> in your project
|
||
directory.</p>
|
||
|
||
<pre><code>from flask import Flask
|
||
from redis import Redis
|
||
|
||
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></li>
|
||
|
||
<li><p>Create another file called <code>requirements.txt</code> in your project directory and
|
||
add the following:</p>
|
||
|
||
<pre><code>flask
|
||
redis
|
||
</code></pre></li>
|
||
</ol>
|
||
|
||
<p>These define the applications dependencies.</p>
|
||
|
||
<h2 id="step-2-create-a-docker-image">Step 2: Create a Docker image</h2>
|
||
|
||
<p>In this step, you build a new Docker image. The image contains all the
|
||
dependencies the Python application requires, including Python itself.</p>
|
||
|
||
<ol>
|
||
<li><p>In your project directory create a file named <code>Dockerfile</code> and add the
|
||
following:</p>
|
||
|
||
<pre><code>FROM python:2.7
|
||
ADD . /code
|
||
WORKDIR /code
|
||
RUN pip install -r requirements.txt
|
||
CMD python app.py
|
||
</code></pre></li>
|
||
</ol>
|
||
|
||
<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 the 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="../engine/userguide/containers/dockerimages/#building-an-image-from-a-dockerfile">Docker user guide</a> and the <a href="../engine/reference/builder/">Dockerfile reference</a>.</p>
|
||
|
||
<ol>
|
||
<li><p>Build the image.</p>
|
||
|
||
<pre><code>$ docker build -t web .
|
||
</code></pre></li>
|
||
</ol>
|
||
|
||
<p>This command builds an image named <code>web</code> from the contents of the current
|
||
directory. The command automatically locates the <code>Dockerfile</code>, <code>app.py</code>, and
|
||
<code>requirements.txt</code> files.</p>
|
||
|
||
<h2 id="step-3-define-services">Step 3: Define services</h2>
|
||
|
||
<p>Define a set of services using <code>docker-compose.yml</code>:</p>
|
||
|
||
<ol>
|
||
<li><p>Create a file called docker-compose.yml in your project directory and add
|
||
the following:</p>
|
||
|
||
<pre><code>version: '2'
|
||
services:
|
||
web:
|
||
build: .
|
||
ports:
|
||
- &quot;5000:5000&quot;
|
||
volumes:
|
||
- .:/code
|
||
depends_on:
|
||
- redis
|
||
redis:
|
||
image: redis
|
||
</code></pre></li>
|
||
</ol>
|
||
|
||
<p>This Compose file defines two services, <code>web</code> and <code>redis</code>. The web service:</p>
|
||
|
||
<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>Mounts the project directory on the host to <code>/code</code> inside the container allowing you to modify the code without having to rebuild the image.</li>
|
||
<li>Links the web service to the Redis service.</li>
|
||
</ul>
|
||
|
||
<p>The <code>redis</code> service uses the latest public <a href="https://registry.hub.docker.com/_/redis/">Redis</a> image pulled from the Docker Hub registry.</p>
|
||
|
||
<h2 id="step-4-build-and-run-your-app-with-compose">Step 4: Build and run your app with Compose</h2>
|
||
|
||
<ol>
|
||
<li><p>From your project directory, start up your application.</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/
|
||
web_1 | * Restarting with stat
|
||
</code></pre></li>
|
||
</ol>
|
||
|
||
<p>Compose pulls a Redis image, builds an image for your code, and start the
|
||
services you defined.</p>
|
||
|
||
<ol>
|
||
<li>Enter <code>http://0.0.0.0:5000/</code> in a browser to see the application running.</li>
|
||
</ol>
|
||
|
||
<p>If you&rsquo;re using Docker on Linux natively, then the web app should now be
|
||
listening on port 5000 on your Docker daemon host. If <code>http://0.0.0.0:5000</code>
|
||
doesn&rsquo;t resolve, you can also try <code>http://localhost:5000</code>.</p>
|
||
|
||
<p>If you&rsquo;re using Docker Machine on a Mac, use <code>docker-machine ip MACHINE_VM</code> to get
|
||
the IP address of your Docker host. Then, <code>open http://MACHINE_VM_IP:5000</code> in a
|
||
browser.</p>
|
||
|
||
<p>You should see a message in your browser saying:</p>
|
||
|
||
<p><code>Hello World! I have been seen 1 times.</code></p>
|
||
|
||
<ol>
|
||
<li>Refresh the page.</li>
|
||
</ol>
|
||
|
||
<p>The number should increment.</p>
|
||
|
||
<h2 id="step-5-experiment-with-some-other-commands">Step 5: Experiment with some other commands</h2>
|
||
|
||
<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. You can also install <a href="../compose/completion/">command completion</a> for the bash and zsh shell, which will also show you 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>
|
||
|
||
<h2 id="where-to-go-next">Where to go next</h2>
|
||
|
||
<ul>
|
||
<li>Next, try the quick start guide for <a href="../compose/django/">Django</a>,
|
||
<a href="../compose/rails/">Rails</a>, or <a href="../compose/wordpress/">WordPress</a>.</li>
|
||
<li><a href="../compose/reference/">Explore the full list of Compose commands</a></li>
|
||
<li><a href="../compose/compose-file/">Compose configuration file reference</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Install Compose</title>
|
||
<link>http://docs-stage.docker.com/compose/install/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/install/</guid>
|
||
<description>
|
||
|
||
<h1 id="install-docker-compose">Install Docker Compose</h1>
|
||
|
||
<p>You can run Compose on OS X, Windows and 64-bit Linux. To install it, you&rsquo;ll need to install Docker first.</p>
|
||
|
||
<p>To install Compose, do the following:</p>
|
||
|
||
<ol>
|
||
<li><p>Install Docker Engine:</p>
|
||
|
||
<ul>
|
||
<li><p><a href="../engine/installation/mac/" target="_blank">Mac OS X installation</a></p></li>
|
||
|
||
<li><p><a href="../engine/installation/windows/" target="_blank">Windows installation</a></p></li>
|
||
|
||
<li><p><a href="../engine/installation/ubuntulinux/" target="_blank">Ubuntu installation</a></p></li>
|
||
|
||
<li><p><a href="../engine/installation/" target="_blank">other system installations</a></p></li>
|
||
</ul></li>
|
||
|
||
<li><p>The Docker Toolbox installation includes both Engine and Compose, so Mac and Windows users are done installing. Others should continue to the next step.</p></li>
|
||
|
||
<li><p>Go to the <a href="https://github.com/docker/compose/releases" target="_blank">Compose repository release page on GitHub</a>.</p></li>
|
||
|
||
<li><p>Follow the instructions from the release page and run the <code>curl</code> command,
|
||
which the release page specifies, in your terminal.</p>
|
||
|
||
<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 below, then <code>exit</code>.</p>
|
||
</blockquote>
|
||
|
||
<p>The following is an example command illustrating the format:</p>
|
||
|
||
<pre><code>curl -L https://github.com/docker/compose/releases/download/1.7.1/docker-compose-`uname -s`-`uname -m` &gt; /usr/local/bin/docker-compose
|
||
</code></pre>
|
||
|
||
<p>If you have problems installing with <code>curl</code>, see
|
||
<a href="#alternative-install-options">Alternative Install Options</a>.</p></li>
|
||
|
||
<li><p>Apply executable permissions to the binary:</p>
|
||
|
||
<pre><code>$ chmod +x /usr/local/bin/docker-compose
|
||
</code></pre></li>
|
||
|
||
<li><p>Optionally, install <a href="../compose/completion/">command completion</a> for the
|
||
<code>bash</code> and <code>zsh</code> shell.</p></li>
|
||
|
||
<li><p>Test the installation.</p>
|
||
|
||
<pre><code>$ docker-compose --version
|
||
docker-compose version: 1.7.1
|
||
</code></pre></li>
|
||
</ol>
|
||
|
||
<h2 id="alternative-install-options">Alternative install options</h2>
|
||
|
||
<h3 id="install-using-pip">Install using pip</h3>
|
||
|
||
<p>Compose can be installed from <a href="https://pypi.python.org/pypi/docker-compose">pypi</a>
|
||
using <code>pip</code>. If you install using <code>pip</code> it is highly recommended that you use a
|
||
<a href="https://virtualenv.pypa.io/en/latest/">virtualenv</a> because many operating systems
|
||
have python system packages that conflict with docker-compose dependencies. See
|
||
the <a href="http://docs.python-guide.org/en/latest/dev/virtualenvs/">virtualenv tutorial</a>
|
||
to get started.</p>
|
||
|
||
<pre><code>$ pip install docker-compose
|
||
</code></pre>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> pip version 6.0 or greater is required</p>
|
||
</blockquote>
|
||
|
||
<h3 id="install-as-a-container">Install as a container</h3>
|
||
|
||
<p>Compose can also be run inside a container, from a small bash script wrapper.
|
||
To install compose as a container run:</p>
|
||
|
||
<pre><code>$ curl -L https://github.com/docker/compose/releases/download/1.7.1/run.sh &gt; /usr/local/bin/docker-compose
|
||
$ chmod +x /usr/local/bin/docker-compose
|
||
</code></pre>
|
||
|
||
<h2 id="master-builds">Master builds</h2>
|
||
|
||
<p>If you&rsquo;re interested in trying out a pre-release build you can download a
|
||
binary from <a href="https://dl.bintray.com/docker-compose/master/">https://dl.bintray.com/docker-compose/master/</a>. Pre-release
|
||
builds allow you to try out new features before they are released, but may
|
||
be less stable.</p>
|
||
|
||
<h2 id="upgrading">Upgrading</h2>
|
||
|
||
<p>If you&rsquo;re upgrading 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 use compose 1.5.x to 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 -v myapp_web_1 myapp_db_1 ...
|
||
</code></pre>
|
||
|
||
<h2 id="uninstallation">Uninstallation</h2>
|
||
|
||
<p>To uninstall Docker Compose if you installed using <code>curl</code>:</p>
|
||
|
||
<pre><code>$ rm /usr/local/bin/docker-compose
|
||
</code></pre>
|
||
|
||
<p>To uninstall Docker Compose if you installed using <code>pip</code>:</p>
|
||
|
||
<pre><code>$ pip uninstall docker-compose
|
||
</code></pre>
|
||
|
||
<blockquote>
|
||
<p><strong>Note</strong>: If you get a &ldquo;Permission denied&rdquo; error using either of the above
|
||
methods, you probably do not have the proper permissions to remove
|
||
<code>docker-compose</code>. To force the removal, prepend <code>sudo</code> to either of the above
|
||
commands and run again.</p>
|
||
</blockquote>
|
||
|
||
<h2 id="where-to-go-next">Where to go next</h2>
|
||
|
||
<ul>
|
||
<li><a href="../compose/">User guide</a></li>
|
||
<li><a href="../compose/gettingstarted/">Getting Started</a></li>
|
||
<li><a href="../compose/django/">Get started with Django</a></li>
|
||
<li><a href="../compose/rails/">Get started with Rails</a></li>
|
||
<li><a href="../compose/wordpress/">Get started with WordPress</a></li>
|
||
<li><a href="../compose/reference/">Command line reference</a></li>
|
||
<li><a href="../compose/compose-file/">Compose file reference</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Link Environment Variables</title>
|
||
<link>http://docs-stage.docker.com/compose/link-env-deprecated/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/link-env-deprecated/</guid>
|
||
<description>
|
||
|
||
<h1 id="link-environment-variables-reference">Link environment variables reference</h1>
|
||
|
||
<blockquote>
|
||
<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="../compose/compose-file/#links">docker-compose.yml documentation</a> for details.</p>
|
||
|
||
<p>Environment variables will only be populated if you&rsquo;re using the <a href="../compose/compose-file/#versioning">legacy version 1 Compose file format</a>.</p>
|
||
</blockquote>
|
||
|
||
<p>Compose uses <a href="../engine/userguide/networking/default_network/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="related-information">Related Information</h2>
|
||
|
||
<ul>
|
||
<li><a href="../compose/">User guide</a></li>
|
||
<li><a href="../compose/install/">Installing Compose</a></li>
|
||
<li><a href="../compose/reference/">Command line reference</a></li>
|
||
<li><a href="../compose/compose-file/">Compose file reference</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Networking in Compose</title>
|
||
<link>http://docs-stage.docker.com/compose/networking/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/networking/</guid>
|
||
<description>
|
||
|
||
<h1 id="networking-in-compose">Networking in Compose</h1>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> This document only applies if you&rsquo;re using <a href="../compose/compose-file/#versioning">version 2 of the Compose file format</a>. Networking features are not supported for version 1 (legacy) Compose files.</p>
|
||
</blockquote>
|
||
|
||
<p>By default Compose sets up a single
|
||
<a href="https://docs.docker.com/engine/reference/commandline/network_create/">network</a> for your app. Each
|
||
container for a service joins the default network and is both <em>reachable</em> by
|
||
other containers on that network, and <em>discoverable</em> by them at a hostname
|
||
identical to the container name.</p>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong> Your app&rsquo;s network is given a name based on the &ldquo;project name&rdquo;,
|
||
which is based on the name of the directory it lives in. You can override the
|
||
project name with either the <a href="../compose/reference/overview/"><code>--project-name</code>
|
||
flag</a> or the <a href="../compose/reference/envvars/#compose-project-name"><code>COMPOSE_PROJECT_NAME</code> environment
|
||
variable</a>.</p>
|
||
</blockquote>
|
||
|
||
<p>For example, suppose your app is in a directory called <code>myapp</code>, and your <code>docker-compose.yml</code> looks like this:</p>
|
||
|
||
<pre><code>version: '2'
|
||
|
||
services:
|
||
web:
|
||
build: .
|
||
ports:
|
||
- &quot;8000:8000&quot;
|
||
db:
|
||
image: postgres
|
||
</code></pre>
|
||
|
||
<p>When you run <code>docker-compose up</code>, the following happens:</p>
|
||
|
||
<ol>
|
||
<li>A network called <code>myapp_default</code> is created.</li>
|
||
<li>A container is created using <code>web</code>&rsquo;s configuration. It joins the network
|
||
<code>myapp_default</code> under the name <code>web</code>.</li>
|
||
<li>A container is created using <code>db</code>&rsquo;s configuration. It joins the network
|
||
<code>myapp_default</code> under the name <code>db</code>.</li>
|
||
</ol>
|
||
|
||
<p>Each container can now look up the hostname <code>web</code> or <code>db</code> and
|
||
get back the appropriate container&rsquo;s IP address. For example, <code>web</code>&rsquo;s
|
||
application code could connect to the URL <code>postgres://db:5432</code> and start
|
||
using the Postgres database.</p>
|
||
|
||
<p>Because <code>web</code> explicitly maps a port, it&rsquo;s also accessible from the outside world via port 8000 on your Docker host&rsquo;s network interface.</p>
|
||
|
||
<h2 id="updating-containers">Updating containers</h2>
|
||
|
||
<p>If you make a configuration change to a service and run <code>docker-compose up</code> to update it, the old container will be removed and the new one will join the network under a different IP address but the same name. Running containers will be able to look up that name and connect to the new address, but the old address will stop working.</p>
|
||
|
||
<p>If any containers have connections open to the old container, they will be closed. It is a container&rsquo;s responsibility to detect this condition, look up the name again and reconnect.</p>
|
||
|
||
<h2 id="links">Links</h2>
|
||
|
||
<p>Links allow you to define extra aliases by which a service is reachable from another service. They are not required to enable services to communicate - by default, any service can reach any other service at that service&rsquo;s name. In the following example, <code>db</code> is reachable from <code>web</code> at the hostnames <code>db</code> and <code>database</code>:</p>
|
||
|
||
<pre><code>version: '2'
|
||
services:
|
||
web:
|
||
build: .
|
||
links:
|
||
- &quot;db:database&quot;
|
||
db:
|
||
image: postgres
|
||
</code></pre>
|
||
|
||
<p>See the <a href="../compose/compose-file/#links">links reference</a> for more information.</p>
|
||
|
||
<h2 id="multi-host-networking">Multi-host networking</h2>
|
||
|
||
<p>When <a href="../compose/swarm/">deploying a Compose application to a Swarm cluster</a>, you can make use of the built-in <code>overlay</code> driver to enable multi-host communication between containers with no changes to your Compose file or application code.</p>
|
||
|
||
<p>Consult the <a href="https://docs.docker.com/engine/userguide/networking/get-started-overlay/">Getting started with multi-host networking</a> to see how to set up a Swarm cluster. The cluster will use the <code>overlay</code> driver by default, but you can specify it explicitly if you prefer - see below for how to do this.</p>
|
||
|
||
<h2 id="specifying-custom-networks">Specifying custom networks</h2>
|
||
|
||
<p>Instead of just using the default app network, you can specify your own networks with the top-level <code>networks</code> key. This lets you create more complex topologies and specify <a href="https://docs.docker.com/engine/extend/plugins_network/">custom network drivers</a> and options. You can also use it to connect services to externally-created networks which aren&rsquo;t managed by Compose.</p>
|
||
|
||
<p>Each service can specify what networks to connect to with the <em>service-level</em> <code>networks</code> key, which is a list of names referencing entries under the <em>top-level</em> <code>networks</code> key.</p>
|
||
|
||
<p>Here&rsquo;s an example Compose file defining two custom networks. The <code>proxy</code> service is isolated from the <code>db</code> service, because they do not share a network in common - only <code>app</code> can talk to both.</p>
|
||
|
||
<pre><code>version: '2'
|
||
|
||
services:
|
||
proxy:
|
||
build: ./proxy
|
||
networks:
|
||
- front
|
||
app:
|
||
build: ./app
|
||
networks:
|
||
- front
|
||
- back
|
||
db:
|
||
image: postgres
|
||
networks:
|
||
- back
|
||
|
||
networks:
|
||
front:
|
||
# Use a custom driver
|
||
driver: custom-driver-1
|
||
back:
|
||
# Use a custom driver which takes special options
|
||
driver: custom-driver-2
|
||
driver_opts:
|
||
foo: &quot;1&quot;
|
||
bar: &quot;2&quot;
|
||
</code></pre>
|
||
|
||
<p>Networks can be configured with static IP addresses by setting the <a href="../compose/compose-file/#ipv4-address-ipv6-address">ipv4_address and/or ipv6_address</a> for each attached network.</p>
|
||
|
||
<p>For full details of the network configuration options available, see the following references:</p>
|
||
|
||
<ul>
|
||
<li><a href="../compose/compose-file/#network-configuration-reference">Top-level <code>networks</code> key</a></li>
|
||
<li><a href="../compose/compose-file/#networks">Service-level <code>networks</code> key</a></li>
|
||
</ul>
|
||
|
||
<h2 id="configuring-the-default-network">Configuring the default network</h2>
|
||
|
||
<p>Instead of (or as well as) specifying your own networks, you can also change the settings of the app-wide default network by defining an entry under <code>networks</code> named <code>default</code>:</p>
|
||
|
||
<pre><code>version: '2'
|
||
|
||
services:
|
||
web:
|
||
build: .
|
||
ports:
|
||
- &quot;8000:8000&quot;
|
||
db:
|
||
image: postgres
|
||
|
||
networks:
|
||
default:
|
||
# Use a custom driver
|
||
driver: custom-driver-1
|
||
</code></pre>
|
||
|
||
<h2 id="using-a-pre-existing-network">Using a pre-existing network</h2>
|
||
|
||
<p>If you want your containers to join a pre-existing network, use the <a href="../compose/compose-file/#network-configuration-reference"><code>external</code> option</a>:</p>
|
||
|
||
<pre><code>networks:
|
||
default:
|
||
external:
|
||
name: my-pre-existing-network
|
||
</code></pre>
|
||
|
||
<p>Instead of attemping to create a network called <code>[projectname]_default</code>, Compose will look for a network called <code>my-pre-existing-network</code> and connect your app&rsquo;s containers to it.</p>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Overview of Docker Compose</title>
|
||
<link>http://docs-stage.docker.com/compose/overview/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/overview/</guid>
|
||
<description>
|
||
|
||
<h1 id="overview-of-docker-compose">Overview of Docker Compose</h1>
|
||
|
||
<p>Compose is a tool for defining and running multi-container Docker applications.
|
||
With Compose, you use a Compose file to configure your application&rsquo;s services.
|
||
Then, using a single command, you create and start all the services
|
||
from your configuration. To learn more about all the features of Compose
|
||
see <a href="#features">the list of features</a>.</p>
|
||
|
||
<p>Compose is great for development, testing, and staging environments, as well as
|
||
CI workflows. You can learn more about each case in
|
||
<a href="#common-use-cases">Common Use Cases</a>.</p>
|
||
|
||
<p>Using Compose is basically a three-step process.</p>
|
||
|
||
<ol>
|
||
<li><p>Define your app&rsquo;s environment with a <code>Dockerfile</code> so it can be reproduced
|
||
anywhere.</p></li>
|
||
|
||
<li><p>Define the services that make up your app in <code>docker-compose.yml</code>
|
||
so they can be run together in an isolated environment.</p></li>
|
||
|
||
<li><p>Lastly, run
|
||
<code>docker-compose up</code> and Compose will start and run your entire app.</p></li>
|
||
</ol>
|
||
|
||
<p>A <code>docker-compose.yml</code> looks like this:</p>
|
||
|
||
<pre><code>version: '2'
|
||
services:
|
||
web:
|
||
build: .
|
||
ports:
|
||
- &quot;5000:5000&quot;
|
||
volumes:
|
||
- .:/code
|
||
- logvolume01:/var/log
|
||
links:
|
||
- redis
|
||
redis:
|
||
image: redis
|
||
volumes:
|
||
logvolume01: {}
|
||
</code></pre>
|
||
|
||
<p>For more information about the Compose file, see the
|
||
<a href="../compose/compose-file/">Compose file reference</a></p>
|
||
|
||
<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="../compose/install/">Installing Compose</a></li>
|
||
<li><a href="../compose/gettingstarted/">Getting Started</a></li>
|
||
<li><a href="../compose/django/">Get started with Django</a></li>
|
||
<li><a href="../compose/rails/">Get started with Rails</a></li>
|
||
<li><a href="../compose/wordpress/">Get started with WordPress</a></li>
|
||
<li><a href="../compose/faq/">Frequently asked questions</a></li>
|
||
<li><a href="../compose/reference/">Command line reference</a></li>
|
||
<li><a href="../compose/compose-file/">Compose file reference</a></li>
|
||
</ul>
|
||
|
||
<h2 id="features">Features</h2>
|
||
|
||
<p>The features of Compose that make it effective are:</p>
|
||
|
||
<ul>
|
||
<li><a href="#Multiple-isolated-environments-on-a-single-host">Multiple isolated environments on a single host</a></li>
|
||
<li><a href="#preserve-volume-data-when-containers-are-created">Preserve volume data when containers are created</a></li>
|
||
<li><a href="#only-recreate-containers-that-have-changed">Only recreate containers that have changed</a></li>
|
||
<li><a href="#variables-and-moving-a-composition-between-environments">Variables and moving a composition between environments</a></li>
|
||
</ul>
|
||
|
||
<h3 id="multiple-isolated-environments-on-a-single-host">Multiple isolated environments on a single host</h3>
|
||
|
||
<p>Compose uses a project name to isolate environments from each other. You can make use of this project name in several different contexts:</p>
|
||
|
||
<ul>
|
||
<li>on a dev host, to create multiple copies of a single environment (e.g., you want to run a stable copy for each feature branch of a project)</li>
|
||
<li>on a CI server, to keep builds from interfering with each other, you can set
|
||
the project name to a unique build number</li>
|
||
<li>on a shared host or dev host, to prevent different projects, which may use the
|
||
same service names, from interfering with each other</li>
|
||
</ul>
|
||
|
||
<p>The default project name is the basename of the project directory. You can set
|
||
a custom project name by using the
|
||
<a href="../compose/reference/overview/"><code>-p</code> command line option</a> or the
|
||
<a href="../compose/reference/envvars/#compose-project-name"><code>COMPOSE_PROJECT_NAME</code> environment variable</a>.</p>
|
||
|
||
<h3 id="preserve-volume-data-when-containers-are-created">Preserve volume data when containers are created</h3>
|
||
|
||
<p>Compose preserves all volumes used by your services. When <code>docker-compose up</code>
|
||
runs, if it finds any containers from previous runs, it copies the volumes from
|
||
the old container to the new container. This process ensures that any data
|
||
you&rsquo;ve created in volumes isn&rsquo;t lost.</p>
|
||
|
||
<h3 id="only-recreate-containers-that-have-changed">Only recreate containers that have changed</h3>
|
||
|
||
<p>Compose caches the configuration used to create a container. When you
|
||
restart a service that has not changed, Compose re-uses the existing
|
||
containers. Re-using containers means that you can make changes to your
|
||
environment very quickly.</p>
|
||
|
||
<h3 id="variables-and-moving-a-composition-between-environments">Variables and moving a composition between environments</h3>
|
||
|
||
<p>Compose supports variables in the Compose file. You can use these variables
|
||
to customize your composition for different environments, or different users.
|
||
See <a href="../compose/compose-file/#variable-substitution">Variable substitution</a> for more
|
||
details.</p>
|
||
|
||
<p>You can extend a Compose file using the <code>extends</code> field or by creating multiple
|
||
Compose files. See <a href="../compose/extends/">extends</a> for more details.</p>
|
||
|
||
<h2 id="common-use-cases">Common Use Cases</h2>
|
||
|
||
<p>Compose can be used in many different ways. Some common use cases are outlined
|
||
below.</p>
|
||
|
||
<h3 id="development-environments">Development environments</h3>
|
||
|
||
<p>When you&rsquo;re developing software, the ability to run an application in an
|
||
isolated environment and interact with it is crucial. The Compose command
|
||
line tool can be used to create the environment and interact with it.</p>
|
||
|
||
<p>The <a href="../compose/compose-file/">Compose file</a> provides a way to document and configure
|
||
all of the application&rsquo;s service dependencies (databases, queues, caches,
|
||
web service APIs, etc). Using the Compose command line tool you can create
|
||
and start one or more containers for each dependency with a single command
|
||
(<code>docker-compose up</code>).</p>
|
||
|
||
<p>Together, these features provide a convenient way for developers to get
|
||
started on a project. Compose can reduce a multi-page &ldquo;developer getting
|
||
started guide&rdquo; to a single machine readable Compose file and a few commands.</p>
|
||
|
||
<h3 id="automated-testing-environments">Automated testing environments</h3>
|
||
|
||
<p>An important part of any Continuous Deployment or Continuous Integration process
|
||
is the automated test suite. Automated end-to-end testing requires an
|
||
environment in which to run tests. Compose provides a convenient way to create
|
||
and destroy isolated testing environments for your test suite. By defining the full environment in a <a href="../compose/compose-file/">Compose file</a> you can create and destroy these environments in just a few commands:</p>
|
||
|
||
<pre><code>$ docker-compose up -d
|
||
$ ./run_tests
|
||
$ docker-compose down
|
||
</code></pre>
|
||
|
||
<h3 id="single-host-deployments">Single host deployments</h3>
|
||
|
||
<p>Compose has traditionally been focused on development and testing workflows,
|
||
but with each release we&rsquo;re making progress on more production-oriented features. You can use Compose to deploy to a remote Docker Engine. The Docker Engine may be a single instance provisioned with
|
||
<a href="../machine/overview/">Docker Machine</a> or an entire
|
||
<a href="../swarm/overview/">Docker Swarm</a> cluster.</p>
|
||
|
||
<p>For details on using production-oriented features, see
|
||
<a href="../compose/production/">compose in production</a> in this documentation.</p>
|
||
|
||
<h2 id="release-notes">Release Notes</h2>
|
||
|
||
<p>To see a detailed list of changes for past and current releases of Docker
|
||
Compose, please refer to the
|
||
<a href="https://github.com/docker/compose/blob/master/CHANGELOG.md">CHANGELOG</a>.</p>
|
||
|
||
<h2 id="getting-help">Getting help</h2>
|
||
|
||
<p>Docker Compose is 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 freenode 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/opensource/get-help/">Getting Help project page</a>.</p>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Overview of docker-compose CLI</title>
|
||
<link>http://docs-stage.docker.com/compose/reference/overview/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>http://docs-stage.docker.com/compose/reference/overview/</guid>
|
||
<description>
|
||
|
||
<h1 id="overview-of-docker-compose-cli">Overview of docker-compose CLI</h1>
|
||
|
||
<p>This page provides the usage information for the <code>docker-compose</code> Command.
|
||
You can also see this information by running <code>docker-compose --help</code> from the
|
||
command line.</p>
|
||
|
||
<pre><code>Define and run multi-container applications with Docker.
|
||
|
||
Usage:
|
||
docker-compose [-f=&lt;arg&gt;...] [options] [COMMAND] [ARGS...]
|
||
docker-compose -h|--help
|
||
|
||
Options:
|
||
-f, --file FILE Specify an alternate compose file (default: docker-compose.yml)
|
||
-p, --project-name NAME Specify an alternate project name (default: directory name)
|
||
--verbose Show more output
|
||
-v, --version Print version and exit
|
||
-H, --host HOST Daemon socket to connect to
|
||
|
||
--tls Use TLS; implied by --tlsverify
|
||
--tlscacert CA_PATH Trust certs signed only by this CA
|
||
--tlscert CLIENT_CERT_PATH Path to TLS certificate file
|
||
--tlskey TLS_KEY_PATH Path to TLS key file
|
||
--tlsverify Use TLS and verify the remote
|
||
--skip-hostname-check Don't check the daemon's hostname against the name specified
|
||
in the client certificate (for example if your docker host
|
||
is an IP address)
|
||
|
||
Commands:
|
||
build Build or rebuild services
|
||
config Validate and view the compose file
|
||
create Create services
|
||
down Stop and remove containers, networks, images, and volumes
|
||
events Receive real time events from containers
|
||
help Get help on a command
|
||
kill Kill containers
|
||
logs View output from containers
|
||
pause Pause services
|
||
port Print the public port for a port binding
|
||
ps List containers
|
||
pull Pulls service images
|
||
restart Restart services
|
||
rm Remove stopped containers
|
||
run Run a one-off command
|
||
scale Set number of containers for a service
|
||
start Start services
|
||
stop Stop services
|
||
unpause Unpause services
|
||
up Create and start containers
|
||
version Show the Docker-Compose version information
|
||
|
||
</code></pre>
|
||
|
||
<p>The Docker Compose binary. You use this command to build and manage multiple
|
||
services in Docker containers.</p>
|
||
|
||
<p>Use the <code>-f</code> flag to specify the location of a Compose configuration file. You
|
||
can supply multiple <code>-f</code> configuration files. When you supply multiple files,
|
||
Compose combines them into a single configuration. Compose builds the
|
||
configuration in the order you supply the files. Subsequent files override and
|
||
add to their successors.</p>
|
||
|
||
<p>For example, consider this command line:</p>
|
||
|
||
<pre><code>$ docker-compose -f docker-compose.yml -f docker-compose.admin.yml run backup_db`
|
||
</code></pre>
|
||
|
||
<p>The <code>docker-compose.yml</code> file might specify a <code>webapp</code> service.</p>
|
||
|
||
<pre><code>webapp:
|
||
image: examples/web
|
||
ports:
|
||
- &quot;8000:8000&quot;
|
||
volumes:
|
||
- &quot;/data&quot;
|
||
</code></pre>
|
||
|
||
<p>If the <code>docker-compose.admin.yml</code> also specifies this same service, any matching
|
||
fields will override the previous file. New values, add to the <code>webapp</code> service
|
||
configuration.</p>
|
||
|
||
<pre><code>webapp:
|
||
build: .
|
||
environment:
|
||
- DEBUG=1
|
||
</code></pre>
|
||
|
||
<p>Use a <code>-f</code> with <code>-</code> (dash) as the filename to read the configuration from
|
||
stdin. When stdin is used all paths in the configuration are
|
||
relative to the current working directory.</p>
|
||
|
||
<p>The <code>-f</code> flag is optional. If you don&rsquo;t provide this flag on the command line,
|
||
Compose traverses the working directory and its parent directories looking for a
|
||
<code>docker-compose.yml</code> and a <code>docker-compose.override.yml</code> file. You must
|
||
supply at least the <code>docker-compose.yml</code> file. If both files are present on the
|
||
same directory level, Compose combines the two files into a single configuration.
|
||
The configuration in the <code>docker-compose.override.yml</code> file is applied over and
|
||
in addition to the values in the <code>docker-compose.yml</code> file.</p>
|
||
|
||
<p>See also the <code>COMPOSE_FILE</code> <a href="../compose/reference/envvars/#compose-file">environment variable</a>.</p>
|
||
|
||
<p>Each configuration has a project name. If you supply a <code>-p</code> flag, you can
|
||
specify a project name. If you don&rsquo;t specify the flag, Compose uses the current
|
||
directory name. See also the <code>COMPOSE_PROJECT_NAME</code> <a href="../compose/reference/envvars/#compose-project-name">environment variable</a></p>
|
||
|
||
<h2 id="where-to-go-next">Where to go next</h2>
|
||
|
||
<ul>
|
||
<li><a href="../compose/reference/envvars/">CLI environment variables</a></li>
|
||
</ul>
|
||
</description>
|
||
</item>
|
||
|
||
</channel>
|
||
</rss> |