mirror of https://github.com/docker/compose.git
Merge pull request #4005 from johndmulhausen/master
Remove old documentation source, add README on migration
This commit is contained in:
commit
85d6d7955f
|
@ -1,8 +0,0 @@
|
|||
FROM docs/base:oss
|
||||
MAINTAINER Docker Docs <docs@docker.com>
|
||||
|
||||
ENV PROJECT=compose
|
||||
# To get the git info for this repo
|
||||
COPY . /src
|
||||
RUN rm -rf /docs/content/$PROJECT/
|
||||
COPY . /docs/content/$PROJECT/
|
|
@ -1,38 +0,0 @@
|
|||
.PHONY: all default docs docs-build docs-shell shell test
|
||||
|
||||
# to allow `make DOCSDIR=1 docs-shell` (to create a bind mount in docs)
|
||||
DOCS_MOUNT := $(if $(DOCSDIR),-v $(CURDIR):/docs/content/compose)
|
||||
|
||||
# to allow `make DOCSPORT=9000 docs`
|
||||
DOCSPORT := 8000
|
||||
|
||||
# Get the IP ADDRESS
|
||||
DOCKER_IP=$(shell python -c "import urlparse ; print urlparse.urlparse('$(DOCKER_HOST)').hostname or ''")
|
||||
HUGO_BASE_URL=$(shell test -z "$(DOCKER_IP)" && echo localhost || echo "$(DOCKER_IP)")
|
||||
HUGO_BIND_IP=0.0.0.0
|
||||
|
||||
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
|
||||
GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")
|
||||
DOCKER_DOCS_IMAGE := docker-docs$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN))
|
||||
|
||||
DOCKER_RUN_DOCS := docker run --rm -it $(DOCS_MOUNT) -e AWS_S3_BUCKET -e NOCACHE
|
||||
|
||||
# for some docs workarounds (see below in "docs-build" target)
|
||||
GITCOMMIT := $(shell git rev-parse --short HEAD 2>/dev/null)
|
||||
|
||||
default: docs
|
||||
|
||||
docs: docs-build
|
||||
$(DOCKER_RUN_DOCS) -p $(if $(DOCSPORT),$(DOCSPORT):)8000 -e DOCKERHOST "$(DOCKER_DOCS_IMAGE)" hugo server --port=$(DOCSPORT) --baseUrl=$(HUGO_BASE_URL) --bind=$(HUGO_BIND_IP) --watch
|
||||
|
||||
docs-draft: docs-build
|
||||
$(DOCKER_RUN_DOCS) -p $(if $(DOCSPORT),$(DOCSPORT):)8000 -e DOCKERHOST "$(DOCKER_DOCS_IMAGE)" hugo server --buildDrafts="true" --port=$(DOCSPORT) --baseUrl=$(HUGO_BASE_URL) --bind=$(HUGO_BIND_IP)
|
||||
|
||||
docs-shell: docs-build
|
||||
$(DOCKER_RUN_DOCS) -p $(if $(DOCSPORT),$(DOCSPORT):)8000 "$(DOCKER_DOCS_IMAGE)" bash
|
||||
|
||||
test: docs-build
|
||||
$(DOCKER_RUN_DOCS) "$(DOCKER_DOCS_IMAGE)"
|
||||
|
||||
docs-build:
|
||||
docker build -t "$(DOCKER_DOCS_IMAGE)" .
|
|
@ -1,86 +1,10 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
draft = true
|
||||
title = "Compose README"
|
||||
description = "Compose README"
|
||||
keywords = ["Docker, documentation, manual, guide, reference, api"]
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
# The docs have been moved!
|
||||
|
||||
# Contributing to the Docker Compose documentation
|
||||
The documentation for Compose has been merged into
|
||||
[the general documentation repo](https://github.com/docker/docker.github.io).
|
||||
|
||||
The documentation in this directory is part of the [https://docs.docker.com](https://docs.docker.com) website. Docker uses [the Hugo static generator](http://gohugo.io/overview/introduction/) to convert project Markdown files to a static HTML site.
|
||||
The docs for Compose are now here:
|
||||
https://github.com/docker/docker.github.io/tree/master/compose
|
||||
|
||||
You don't need to be a Hugo expert to contribute to the compose documentation. If you are familiar with Markdown, you can modify the content in the `docs` files.
|
||||
|
||||
If you want to add a new file or change the location of the document in the menu, you do need to know a little more.
|
||||
|
||||
## Documentation contributing workflow
|
||||
|
||||
1. Edit a Markdown file in the tree.
|
||||
|
||||
2. Save your changes.
|
||||
|
||||
3. Make sure you are in the `docs` subdirectory.
|
||||
|
||||
4. Build the documentation.
|
||||
|
||||
$ make docs
|
||||
---> ffcf3f6c4e97
|
||||
Removing intermediate container a676414185e8
|
||||
Successfully built ffcf3f6c4e97
|
||||
docker run --rm -it -e AWS_S3_BUCKET -e NOCACHE -p 8000:8000 -e DOCKERHOST "docs-base:test-tooling" hugo server --port=8000 --baseUrl=192.168.59.103 --bind=0.0.0.0
|
||||
ERROR: 2015/06/13 MenuEntry's .Url is deprecated and will be removed in Hugo 0.15. Use .URL instead.
|
||||
0 of 4 drafts rendered
|
||||
0 future content
|
||||
12 pages created
|
||||
0 paginator pages created
|
||||
0 tags created
|
||||
0 categories created
|
||||
in 55 ms
|
||||
Serving pages from /docs/public
|
||||
Web Server is available at http://0.0.0.0:8000/
|
||||
Press Ctrl+C to stop
|
||||
|
||||
5. Open the available server in your browser.
|
||||
|
||||
The documentation server has the complete menu but only the Docker Compose
|
||||
documentation resolves. You can't access the other project docs from this
|
||||
localized build.
|
||||
|
||||
## Tips on Hugo metadata and menu positioning
|
||||
|
||||
The top of each Docker Compose documentation file contains TOML metadata. The metadata is commented out to prevent it from appearing in GitHub.
|
||||
|
||||
<!--[metadata]>
|
||||
+++
|
||||
title = "Extending services in Compose"
|
||||
description = "How to use Docker Compose's extends keyword to share configuration between files and projects"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, documentation, docs"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=2
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
The metadata alone has this structure:
|
||||
|
||||
+++
|
||||
title = "Extending services in Compose"
|
||||
description = "How to use Docker Compose's extends keyword to share configuration between files and projects"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, documentation, docs"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=2
|
||||
+++
|
||||
|
||||
The `[menu.main]` section refers to navigation defined [in the main Docker menu](https://github.com/docker/docs-base/blob/hugo/config.toml). This metadata says *add a menu item called* Extending services in Compose *to the menu with the* `smn_workdw_compose` *identifier*. If you locate the menu in the configuration, you'll find *Create multi-container applications* is the menu title.
|
||||
|
||||
You can move an article in the tree by specifying a new parent. You can shift the location of the item by changing its weight. Higher numbers are heavier and shift the item to the bottom of menu. Low or no numbers shift it up.
|
||||
|
||||
|
||||
## Other key documentation repositories
|
||||
|
||||
The `docker/docs-base` repository contains [the Hugo theme and menu configuration](https://github.com/docker/docs-base). If you open the `Dockerfile` you'll see the `make docs` relies on this as a base image for building the Compose documentation.
|
||||
|
||||
The `docker/docs.docker.com` repository contains [build system for building the Docker documentation site](https://github.com/docker/docs.docker.com). Fork this repository to build the entire documentation site.
|
||||
As always, the docs remain open-source and we appreciate your feedback and
|
||||
pull requests!
|
||||
|
|
209
docs/bundles.md
209
docs/bundles.md
|
@ -1,209 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Docker Stacks and Distributed Application Bundles"
|
||||
description = "Description of Docker and Compose's experimental support for application bundles"
|
||||
keywords = ["documentation, docs, docker, compose, bundles, stacks"]
|
||||
advisory = "experimental"
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Docker Stacks and Distributed Application Bundles (experimental)
|
||||
|
||||
> **Note**: This is a copy of the [Docker Stacks and Distributed Application
|
||||
> Bundles](https://github.com/docker/docker/blob/v1.12.0-rc4/experimental/docker-stacks-and-bundles.md)
|
||||
> document in the [docker/docker repo](https://github.com/docker/docker).
|
||||
|
||||
## Overview
|
||||
|
||||
Docker Stacks and Distributed Application Bundles are experimental features
|
||||
introduced in Docker 1.12 and Docker Compose 1.8, alongside the concept of
|
||||
swarm mode, and Nodes and Services in the Engine API.
|
||||
|
||||
A Dockerfile can be built into an image, and containers can be created from
|
||||
that image. Similarly, a docker-compose.yml can be built into a **distributed
|
||||
application bundle**, and **stacks** can be created from that bundle. In that
|
||||
sense, the bundle is a multi-services distributable image format.
|
||||
|
||||
As of Docker 1.12 and Compose 1.8, the features are experimental. Neither
|
||||
Docker Engine nor the Docker Registry support distribution of bundles.
|
||||
|
||||
## Producing a bundle
|
||||
|
||||
The easiest way to produce a bundle is to generate it using `docker-compose`
|
||||
from an existing `docker-compose.yml`. Of course, that's just *one* possible way
|
||||
to proceed, in the same way that `docker build` isn't the only way to produce a
|
||||
Docker image.
|
||||
|
||||
From `docker-compose`:
|
||||
|
||||
```bash
|
||||
$ docker-compose bundle
|
||||
WARNING: Unsupported key 'network_mode' in services.nsqd - ignoring
|
||||
WARNING: Unsupported key 'links' in services.nsqd - ignoring
|
||||
WARNING: Unsupported key 'volumes' in services.nsqd - ignoring
|
||||
[...]
|
||||
Wrote bundle to vossibility-stack.dab
|
||||
```
|
||||
|
||||
## Creating a stack from a bundle
|
||||
|
||||
> **Note**: Because support for stacks and bundles is in the experimental stage,
|
||||
> you need to install an experimental build of Docker Engine to use it.
|
||||
>
|
||||
> If you're on Mac or Windows, download the “Beta channel” version of
|
||||
> [Docker for Mac](https://docs.docker.com/docker-for-mac/) or
|
||||
> [Docker for Windows](https://docs.docker.com/docker-for-windows/) to install
|
||||
> it. If you're on Linux, follow the instructions in the
|
||||
> [experimental build README](https://github.com/docker/docker/blob/master/experimental/README.md).
|
||||
|
||||
A stack is created using the `docker deploy` command:
|
||||
|
||||
```bash
|
||||
# docker deploy --help
|
||||
|
||||
Usage: docker deploy [OPTIONS] STACK
|
||||
|
||||
Create and update a stack
|
||||
|
||||
Options:
|
||||
--file string Path to a Distributed Application Bundle file (Default: STACK.dab)
|
||||
--help Print usage
|
||||
--with-registry-auth Send registry authentication details to Swarm agents
|
||||
```
|
||||
|
||||
Let's deploy the stack created before:
|
||||
|
||||
```bash
|
||||
# docker deploy vossibility-stack
|
||||
Loading bundle from vossibility-stack.dab
|
||||
Creating service vossibility-stack_elasticsearch
|
||||
Creating service vossibility-stack_kibana
|
||||
Creating service vossibility-stack_logstash
|
||||
Creating service vossibility-stack_lookupd
|
||||
Creating service vossibility-stack_nsqd
|
||||
Creating service vossibility-stack_vossibility-collector
|
||||
```
|
||||
|
||||
We can verify that services were correctly created:
|
||||
|
||||
```bash
|
||||
# docker service ls
|
||||
ID NAME REPLICAS IMAGE
|
||||
COMMAND
|
||||
29bv0vnlm903 vossibility-stack_lookupd 1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 /nsqlookupd
|
||||
4awt47624qwh vossibility-stack_nsqd 1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 /nsqd --data-path=/data --lookupd-tcp-address=lookupd:4160
|
||||
4tjx9biia6fs vossibility-stack_elasticsearch 1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa
|
||||
7563uuzr9eys vossibility-stack_kibana 1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03
|
||||
9gc5m4met4he vossibility-stack_logstash 1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe logstash -f /etc/logstash/conf.d/logstash.conf
|
||||
axqh55ipl40h vossibility-stack_vossibility-collector 1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba --config /config/config.toml --debug
|
||||
```
|
||||
|
||||
## Managing stacks
|
||||
|
||||
Stacks are managed using the `docker stack` command:
|
||||
|
||||
```bash
|
||||
# docker stack --help
|
||||
|
||||
Usage: docker stack COMMAND
|
||||
|
||||
Manage Docker stacks
|
||||
|
||||
Options:
|
||||
--help Print usage
|
||||
|
||||
Commands:
|
||||
config Print the stack configuration
|
||||
deploy Create and update a stack
|
||||
rm Remove the stack
|
||||
services List the services in the stack
|
||||
tasks List the tasks in the stack
|
||||
|
||||
Run 'docker stack COMMAND --help' for more information on a command.
|
||||
```
|
||||
|
||||
## Bundle file format
|
||||
|
||||
Distributed application bundles are described in a JSON format. When bundles
|
||||
are persisted as files, the file extension is `.dab`.
|
||||
|
||||
A bundle has two top-level fields: `version` and `services`. The version used
|
||||
by Docker 1.12 tools is `0.1`.
|
||||
|
||||
`services` in the bundle are the services that comprise the app. They
|
||||
correspond to the new `Service` object introduced in the 1.12 Docker Engine API.
|
||||
|
||||
A service has the following fields:
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
Image (required) <code>string</code>
|
||||
</dt>
|
||||
<dd>
|
||||
The image that the service will run. Docker images should be referenced
|
||||
with full content hash to fully specify the deployment artifact for the
|
||||
service. Example:
|
||||
<code>postgres@sha256:e0a230a9f5b4e1b8b03bb3e8cf7322b0e42b7838c5c87f4545edb48f5eb8f077</code>
|
||||
</dd>
|
||||
<dt>
|
||||
Command <code>[]string</code>
|
||||
</dt>
|
||||
<dd>
|
||||
Command to run in service containers.
|
||||
</dd>
|
||||
<dt>
|
||||
Args <code>[]string</code>
|
||||
</dt>
|
||||
<dd>
|
||||
Arguments passed to the service containers.
|
||||
</dd>
|
||||
<dt>
|
||||
Env <code>[]string</code>
|
||||
</dt>
|
||||
<dd>
|
||||
Environment variables.
|
||||
</dd>
|
||||
<dt>
|
||||
Labels <code>map[string]string</code>
|
||||
</dt>
|
||||
<dd>
|
||||
Labels used for setting meta data on services.
|
||||
</dd>
|
||||
<dt>
|
||||
Ports <code>[]Port</code>
|
||||
</dt>
|
||||
<dd>
|
||||
Service ports (composed of <code>Port</code> (<code>int</code>) and
|
||||
<code>Protocol</code> (<code>string</code>). A service description can
|
||||
only specify the container port to be exposed. These ports can be
|
||||
mapped on runtime hosts at the operator's discretion.
|
||||
</dd>
|
||||
|
||||
<dt>
|
||||
WorkingDir <code>string</code>
|
||||
</dt>
|
||||
<dd>
|
||||
Working directory inside the service containers.
|
||||
</dd>
|
||||
|
||||
<dt>
|
||||
User <code>string</code>
|
||||
</dt>
|
||||
<dd>
|
||||
Username or UID (format: <code><name|uid>[:<group|gid>]</code>).
|
||||
</dd>
|
||||
|
||||
<dt>
|
||||
Networks <code>[]string</code>
|
||||
</dt>
|
||||
<dd>
|
||||
Networks that the service containers should be connected to. An entity
|
||||
deploying a bundle should create networks as needed.
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
> **Note:** Some configuration options are not yet supported in the DAB format,
|
||||
> including volume mounts.
|
|
@ -1,68 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Command-line Completion"
|
||||
description = "Compose CLI reference"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, reference"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=88
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# Command-line Completion
|
||||
|
||||
Compose comes with [command completion](http://en.wikipedia.org/wiki/Command-line_completion)
|
||||
for the bash and zsh shell.
|
||||
|
||||
## Installing Command Completion
|
||||
|
||||
### Bash
|
||||
|
||||
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 `brew install bash-completion`
|
||||
|
||||
Place the completion script in `/etc/bash_completion.d/` (`/usr/local/etc/bash_completion.d/` on a Mac), using e.g.
|
||||
|
||||
curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
|
||||
|
||||
Completion will be available upon next login.
|
||||
|
||||
### Zsh
|
||||
|
||||
Place the completion script in your `/path/to/zsh/completion`, using e.g. `~/.zsh/completion/`
|
||||
|
||||
mkdir -p ~/.zsh/completion
|
||||
curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/zsh/_docker-compose > ~/.zsh/completion/_docker-compose
|
||||
|
||||
Include the directory in your `$fpath`, e.g. by adding in `~/.zshrc`
|
||||
|
||||
fpath=(~/.zsh/completion $fpath)
|
||||
|
||||
Make sure `compinit` is loaded or do it by adding in `~/.zshrc`
|
||||
|
||||
autoload -Uz compinit && compinit -i
|
||||
|
||||
Then reload your shell
|
||||
|
||||
exec $SHELL -l
|
||||
|
||||
## Available completions
|
||||
|
||||
Depending on what you typed on the command line so far, it will complete
|
||||
|
||||
- available docker-compose commands
|
||||
- options that are available for a particular command
|
||||
- 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 `docker-compose scale`, completed service names will automatically have "=" appended.
|
||||
- arguments for selected options, e.g. `docker-compose kill -s` will complete some signals like SIGHUP and SIGUSR1.
|
||||
|
||||
Enjoy working with Compose faster and with less typos!
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [User guide](index.md)
|
||||
- [Installing Compose](install.md)
|
||||
- [Get started with Django](django.md)
|
||||
- [Get started with Rails](rails.md)
|
||||
- [Get started with WordPress](wordpress.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
1223
docs/compose-file.md
1223
docs/compose-file.md
File diff suppressed because it is too large
Load Diff
194
docs/django.md
194
docs/django.md
|
@ -1,194 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Quickstart: Compose and Django"
|
||||
description = "Getting started with Docker Compose and Django"
|
||||
keywords = ["documentation, docs, docker, compose, orchestration, containers"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=4
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Quickstart: Docker Compose and Django
|
||||
|
||||
This quick-start guide demonstrates how to use Docker Compose to set up and run a simple Django/PostgreSQL app. Before starting, you'll need to have
|
||||
[Compose installed](install.md).
|
||||
|
||||
### Define the project components
|
||||
|
||||
For this project, you need to create a Dockerfile, a Python dependencies file,
|
||||
and a `docker-compose.yml` file.
|
||||
|
||||
1. Create an empty project directory.
|
||||
|
||||
You can name the directory something easy for you to remember. This directory is the context for your application image. The directory should only contain resources to build that image.
|
||||
|
||||
2. Create a new file called `Dockerfile` in your project directory.
|
||||
|
||||
The Dockerfile defines an application's image content via one or more build
|
||||
commands that configure that image. Once built, you can run the image in a
|
||||
container. For more information on `Dockerfiles`, see the [Docker user
|
||||
guide](/engine/tutorials/dockerimages.md#building-an-image-from-a-dockerfile)
|
||||
and the [Dockerfile reference](/engine/reference/builder.md).
|
||||
|
||||
3. Add the following content to the `Dockerfile`.
|
||||
|
||||
FROM python:2.7
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
RUN mkdir /code
|
||||
WORKDIR /code
|
||||
ADD requirements.txt /code/
|
||||
RUN pip install -r requirements.txt
|
||||
ADD . /code/
|
||||
|
||||
This `Dockerfile` starts with a Python 2.7 base image. The base image is
|
||||
modified by adding a new `code` directory. The base image is further modified
|
||||
by installing the Python requirements defined in the `requirements.txt` file.
|
||||
|
||||
4. Save and close the `Dockerfile`.
|
||||
|
||||
5. Create a `requirements.txt` in your project directory.
|
||||
|
||||
This file is used by the `RUN pip install -r requirements.txt` command in your `Dockerfile`.
|
||||
|
||||
6. Add the required software in the file.
|
||||
|
||||
Django
|
||||
psycopg2
|
||||
|
||||
7. Save and close the `requirements.txt` file.
|
||||
|
||||
8. Create a file called `docker-compose.yml` in your project directory.
|
||||
|
||||
The `docker-compose.yml` file describes the services that make your app. In
|
||||
this example those services are a web server and database. The compose file
|
||||
also describes which Docker images these services use, how they link
|
||||
together, any volumes they might need mounted inside the containers.
|
||||
Finally, the `docker-compose.yml` file describes which ports these services
|
||||
expose. See the [`docker-compose.yml` reference](compose-file.md) for more
|
||||
information on how this file works.
|
||||
|
||||
9. Add the following configuration to the file.
|
||||
|
||||
version: '2'
|
||||
services:
|
||||
db:
|
||||
image: postgres
|
||||
web:
|
||||
build: .
|
||||
command: python manage.py runserver 0.0.0.0:8000
|
||||
volumes:
|
||||
- .:/code
|
||||
ports:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
This file defines two services: The `db` service and the `web` service.
|
||||
|
||||
10. Save and close the `docker-compose.yml` file.
|
||||
|
||||
### Create a Django project
|
||||
|
||||
In this step, you create a Django started project by building the image from the build context defined in the previous procedure.
|
||||
|
||||
1. Change to the root of your project directory.
|
||||
|
||||
2. Create the Django project using the `docker-compose` command.
|
||||
|
||||
$ docker-compose run web django-admin.py startproject composeexample .
|
||||
|
||||
This instructs Compose to run `django-admin.py startproject composeeexample`
|
||||
in a container, using the `web` service's image and configuration. Because
|
||||
the `web` image doesn't exist yet, Compose builds it from the current
|
||||
directory, as specified by the `build: .` line in `docker-compose.yml`.
|
||||
|
||||
Once the `web` service image is built, Compose runs it and executes the
|
||||
`django-admin.py startproject` command in the container. This command
|
||||
instructs Django to create a set of files and directories representing a
|
||||
Django project.
|
||||
|
||||
3. After the `docker-compose` command completes, list the contents of your project.
|
||||
|
||||
$ ls -l
|
||||
drwxr-xr-x 2 root root composeexample
|
||||
-rw-rw-r-- 1 user user docker-compose.yml
|
||||
-rw-rw-r-- 1 user user Dockerfile
|
||||
-rwxr-xr-x 1 root root manage.py
|
||||
-rw-rw-r-- 1 user user requirements.txt
|
||||
|
||||
If you are running Docker on Linux, the files `django-admin` created are owned
|
||||
by root. This happens because the container runs as the root user. Change the
|
||||
ownership of the the new files.
|
||||
|
||||
sudo chown -R $USER:$USER .
|
||||
|
||||
If you are running Docker on Mac or Windows, you should already have ownership
|
||||
of all files, including those generated by `django-admin`. List the files just
|
||||
verify this.
|
||||
|
||||
$ ls -l
|
||||
total 32
|
||||
-rw-r--r-- 1 user staff 145 Feb 13 23:00 Dockerfile
|
||||
drwxr-xr-x 6 user staff 204 Feb 13 23:07 composeexample
|
||||
-rw-r--r-- 1 user staff 159 Feb 13 23:02 docker-compose.yml
|
||||
-rwxr-xr-x 1 user staff 257 Feb 13 23:07 manage.py
|
||||
-rw-r--r-- 1 user staff 16 Feb 13 23:01 requirements.txt
|
||||
|
||||
|
||||
### Connect the database
|
||||
|
||||
In this section, you set up the database connection for Django.
|
||||
|
||||
1. In your project directory, edit the `composeexample/settings.py` file.
|
||||
|
||||
2. Replace the `DATABASES = ...` with the following:
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'postgres',
|
||||
'USER': 'postgres',
|
||||
'HOST': 'db',
|
||||
'PORT': 5432,
|
||||
}
|
||||
}
|
||||
|
||||
These settings are determined by the
|
||||
[postgres](https://hub.docker.com/_/postgres/) Docker image
|
||||
specified in `docker-compose.yml`.
|
||||
|
||||
3. Save and close the file.
|
||||
|
||||
4. Run the `docker-compose up` command.
|
||||
|
||||
$ docker-compose up
|
||||
Starting composepractice_db_1...
|
||||
Starting composepractice_web_1...
|
||||
Attaching to composepractice_db_1, composepractice_web_1
|
||||
...
|
||||
db_1 | PostgreSQL init process complete; ready for start up.
|
||||
...
|
||||
db_1 | LOG: database system is ready to accept connections
|
||||
db_1 | LOG: autovacuum launcher started
|
||||
..
|
||||
web_1 | Django version 1.8.4, using settings 'composeexample.settings'
|
||||
web_1 | Starting development server at http://0.0.0.0:8000/
|
||||
web_1 | Quit the server with CONTROL-C.
|
||||
|
||||
At this point, your Django app should be running at port `8000` on your
|
||||
Docker host. If you are using a Docker Machine VM, you can use the
|
||||
`docker-machine ip MACHINE_NAME` to get the IP address.
|
||||
|
||||

|
||||
|
||||
## More Compose documentation
|
||||
|
||||
- [User guide](index.md)
|
||||
- [Installing Compose](install.md)
|
||||
- [Getting Started](gettingstarted.md)
|
||||
- [Get started with Rails](rails.md)
|
||||
- [Get started with WordPress](wordpress.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
|
@ -1,43 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Environment file"
|
||||
description = "Declaring default environment variables in file"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, environment, env file"]
|
||||
[menu.main]
|
||||
parent = "workw_compose"
|
||||
weight=10
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Environment file
|
||||
|
||||
Compose supports declaring default environment variables in an environment
|
||||
file named `.env` placed in the folder `docker-compose` command is executed from
|
||||
*(current working directory)*.
|
||||
|
||||
Compose expects each line in an env file to be in `VAR=VAL` format. Lines
|
||||
beginning with `#` (i.e. comments) are ignored, as are blank lines.
|
||||
|
||||
> Note: Values present in the environment at runtime will always override
|
||||
> those defined inside the `.env` file. Similarly, values passed via
|
||||
> command-line arguments take precedence as well.
|
||||
|
||||
Those environment variables will be used for
|
||||
[variable substitution](compose-file.md#variable-substitution) in your Compose
|
||||
file, but can also be used to define the following
|
||||
[CLI variables](reference/envvars.md):
|
||||
|
||||
- `COMPOSE_API_VERSION`
|
||||
- `COMPOSE_FILE`
|
||||
- `COMPOSE_HTTP_TIMEOUT`
|
||||
- `COMPOSE_PROJECT_NAME`
|
||||
- `DOCKER_CERT_PATH`
|
||||
- `DOCKER_HOST`
|
||||
- `DOCKER_TLS_VERIFY`
|
||||
|
||||
## More Compose documentation
|
||||
|
||||
- [User guide](index.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
|
@ -1,107 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Environment variables in Compose"
|
||||
description = "How to set, use and manage environment variables in Compose"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, environment, variables, env file"]
|
||||
[menu.main]
|
||||
parent = "workw_compose"
|
||||
weight=10
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# Environment variables in Compose
|
||||
|
||||
There are multiple parts of Compose that deal with environment variables in one sense or another. This page should help you find the information you need.
|
||||
|
||||
|
||||
## Substituting environment variables in Compose files
|
||||
|
||||
It's possible to use environment variables in your shell to populate values inside a Compose file:
|
||||
|
||||
web:
|
||||
image: "webapp:${TAG}"
|
||||
|
||||
For more information, see the [Variable substitution](compose-file.md#variable-substitution) section in the Compose file reference.
|
||||
|
||||
|
||||
## Setting environment variables in containers
|
||||
|
||||
You can set environment variables in a service's containers with the ['environment' key](compose-file.md#environment), just like with `docker run -e VARIABLE=VALUE ...`:
|
||||
|
||||
web:
|
||||
environment:
|
||||
- DEBUG=1
|
||||
|
||||
|
||||
## Passing environment variables through to containers
|
||||
|
||||
You can pass environment variables from your shell straight through to a service's containers with the ['environment' key](compose-file.md#environment) by not giving them a value, just like with `docker run -e VARIABLE ...`:
|
||||
|
||||
web:
|
||||
environment:
|
||||
- DEBUG
|
||||
|
||||
The value of the `DEBUG` variable in the container will be taken from the value for the same variable in the shell in which Compose is run.
|
||||
|
||||
|
||||
## The “env_file” configuration option
|
||||
|
||||
You can pass multiple environment variables from an external file through to a service's containers with the ['env_file' option](compose-file.md#env-file), just like with `docker run --env-file=FILE ...`:
|
||||
|
||||
web:
|
||||
env_file:
|
||||
- web-variables.env
|
||||
|
||||
|
||||
## Setting environment variables with 'docker-compose run'
|
||||
|
||||
Just like with `docker run -e`, you can set environment variables on a one-off container with `docker-compose run -e`:
|
||||
|
||||
$ docker-compose run -e DEBUG=1 web python console.py
|
||||
|
||||
You can also pass a variable through from the shell by not giving it a value:
|
||||
|
||||
$ docker-compose run -e DEBUG web python console.py
|
||||
|
||||
The value of the `DEBUG` variable in the container will be taken from the value for the same variable in the shell in which Compose is run.
|
||||
|
||||
|
||||
## The “.env” file
|
||||
|
||||
You can set default values for any environment variables referenced in the Compose file, or used to configure Compose, in an [environment file](env-file.md) named `.env`:
|
||||
|
||||
$ cat .env
|
||||
TAG=v1.5
|
||||
|
||||
$ cat docker-compose.yml
|
||||
version: '2.0'
|
||||
services:
|
||||
web:
|
||||
image: "webapp:${TAG}"
|
||||
|
||||
When you run `docker-compose up`, the `web` service defined above uses the image `webapp:v1.5`. You can verify this with the [config command](reference/config.md), which prints your resolved application config to the terminal:
|
||||
|
||||
$ docker-compose config
|
||||
version: '2.0'
|
||||
services:
|
||||
web:
|
||||
image: 'webapp:v1.5'
|
||||
|
||||
Values in the shell take precedence over those specified in the `.env` file. If you set `TAG` to a different value in your shell, the substitution in `image` uses that instead:
|
||||
|
||||
$ export TAG=v2.0
|
||||
|
||||
$ docker-compose config
|
||||
version: '2.0'
|
||||
services:
|
||||
web:
|
||||
image: 'webapp:v2.0'
|
||||
|
||||
## Configuring Compose using environment variables
|
||||
|
||||
Several environment variables are available for you to configure the Docker Compose command-line behaviour. They begin with `COMPOSE_` or `DOCKER_`, and are documented in [CLI Environment Variables](reference/envvars.md).
|
||||
|
||||
|
||||
## Environment variables created by links
|
||||
|
||||
When using the ['links' option](compose-file.md#links) in a [v1 Compose file](compose-file.md#version-1), environment variables will be created for each link. They are documented in the [Link environment variables reference](link-env-deprecated.md). Please note, however, that these variables are deprecated - you should just use the link alias as a hostname instead.
|
354
docs/extends.md
354
docs/extends.md
|
@ -1,354 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Extending Services in Compose"
|
||||
description = "How to use Docker Compose's extends keyword to share configuration between files and projects"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, documentation, docs"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=20
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Extending services and Compose files
|
||||
|
||||
Compose supports two methods of sharing common configuration:
|
||||
|
||||
1. Extending an entire Compose file by
|
||||
[using multiple Compose files](#multiple-compose-files)
|
||||
2. Extending individual services with [the `extends` field](#extending-services)
|
||||
|
||||
|
||||
## Multiple Compose files
|
||||
|
||||
Using multiple Compose files enables you to customize a Compose application
|
||||
for different environments or different workflows.
|
||||
|
||||
### Understanding multiple Compose files
|
||||
|
||||
By default, Compose reads two files, a `docker-compose.yml` and an optional
|
||||
`docker-compose.override.yml` file. By convention, the `docker-compose.yml`
|
||||
contains your base configuration. The override file, as its name implies, can
|
||||
contain configuration overrides for existing services or entirely new
|
||||
services.
|
||||
|
||||
If a service is defined in both files Compose merges the configurations using
|
||||
the rules described in [Adding and overriding
|
||||
configuration](#adding-and-overriding-configuration).
|
||||
|
||||
To use multiple override files, or an override file with a different name, you
|
||||
can use the `-f` option to specify the list of files. Compose merges files in
|
||||
the order they're specified on the command line. See the [`docker-compose`
|
||||
command reference](./reference/overview.md) for more information about
|
||||
using `-f`.
|
||||
|
||||
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 `-f`). 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.
|
||||
|
||||
### Example use case
|
||||
|
||||
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.
|
||||
|
||||
#### Different environments
|
||||
|
||||
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:
|
||||
|
||||
Start with a base file that defines the canonical configuration for the
|
||||
services.
|
||||
|
||||
**docker-compose.yml**
|
||||
|
||||
web:
|
||||
image: example/my_web_app:latest
|
||||
links:
|
||||
- db
|
||||
- cache
|
||||
|
||||
db:
|
||||
image: postgres:latest
|
||||
|
||||
cache:
|
||||
image: redis:latest
|
||||
|
||||
In this example the development configuration exposes some ports to the
|
||||
host, mounts our code as a volume, and builds the web image.
|
||||
|
||||
**docker-compose.override.yml**
|
||||
|
||||
|
||||
web:
|
||||
build: .
|
||||
volumes:
|
||||
- '.:/code'
|
||||
ports:
|
||||
- 8883:80
|
||||
environment:
|
||||
DEBUG: 'true'
|
||||
|
||||
db:
|
||||
command: '-d'
|
||||
ports:
|
||||
- 5432:5432
|
||||
|
||||
cache:
|
||||
ports:
|
||||
- 6379:6379
|
||||
|
||||
When you run `docker-compose up` it reads the overrides automatically.
|
||||
|
||||
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).
|
||||
|
||||
**docker-compose.prod.yml**
|
||||
|
||||
web:
|
||||
ports:
|
||||
- 80:80
|
||||
environment:
|
||||
PRODUCTION: 'true'
|
||||
|
||||
cache:
|
||||
environment:
|
||||
TTL: '500'
|
||||
|
||||
To deploy with this production Compose file you can run
|
||||
|
||||
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
||||
|
||||
This deploys all three services using the configuration in
|
||||
`docker-compose.yml` and `docker-compose.prod.yml` (but not the
|
||||
dev configuration in `docker-compose.override.yml`).
|
||||
|
||||
|
||||
See [production](production.md) for more information about Compose in
|
||||
production.
|
||||
|
||||
#### Administrative tasks
|
||||
|
||||
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.
|
||||
|
||||
Start with a **docker-compose.yml**.
|
||||
|
||||
web:
|
||||
image: example/my_web_app:latest
|
||||
links:
|
||||
- db
|
||||
|
||||
db:
|
||||
image: postgres:latest
|
||||
|
||||
In a **docker-compose.admin.yml** add a new service to run the database
|
||||
export or backup.
|
||||
|
||||
dbadmin:
|
||||
build: database_admin/
|
||||
links:
|
||||
- db
|
||||
|
||||
To start a normal environment run `docker-compose up -d`. To run a database
|
||||
backup, include the `docker-compose.admin.yml` as well.
|
||||
|
||||
docker-compose -f docker-compose.yml -f docker-compose.admin.yml \
|
||||
run dbadmin db-backup
|
||||
|
||||
|
||||
## Extending services
|
||||
|
||||
Docker Compose's `extends` 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 `extends` you can define a common set of service options in one
|
||||
place and refer to it from anywhere.
|
||||
|
||||
> **Note:** `links`, `volumes_from`, and `depends_on` are never shared between
|
||||
> services using >`extends`. These exceptions exist to avoid
|
||||
> implicit dependencies—you always define `links` and `volumes_from`
|
||||
> 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't result in breakage.
|
||||
|
||||
### Understand the extends configuration
|
||||
|
||||
When defining any service in `docker-compose.yml`, you can declare that you are
|
||||
extending another service like this:
|
||||
|
||||
web:
|
||||
extends:
|
||||
file: common-services.yml
|
||||
service: webapp
|
||||
|
||||
This instructs Compose to re-use the configuration for the `webapp` service
|
||||
defined in the `common-services.yml` file. Suppose that `common-services.yml`
|
||||
looks like this:
|
||||
|
||||
webapp:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- "/data"
|
||||
|
||||
In this case, you'll get exactly the same result as if you wrote
|
||||
`docker-compose.yml` with the same `build`, `ports` and `volumes` configuration
|
||||
values defined directly under `web`.
|
||||
|
||||
You can go further and define (or re-define) configuration locally in
|
||||
`docker-compose.yml`:
|
||||
|
||||
web:
|
||||
extends:
|
||||
file: common-services.yml
|
||||
service: webapp
|
||||
environment:
|
||||
- DEBUG=1
|
||||
cpu_shares: 5
|
||||
|
||||
important_web:
|
||||
extends: web
|
||||
cpu_shares: 10
|
||||
|
||||
You can also write other services and link your `web` service to them:
|
||||
|
||||
web:
|
||||
extends:
|
||||
file: common-services.yml
|
||||
service: webapp
|
||||
environment:
|
||||
- DEBUG=1
|
||||
cpu_shares: 5
|
||||
links:
|
||||
- db
|
||||
db:
|
||||
image: postgres
|
||||
|
||||
### Example use case
|
||||
|
||||
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.
|
||||
|
||||
In a **common.yml** we define the common configuration:
|
||||
|
||||
app:
|
||||
build: .
|
||||
environment:
|
||||
CONFIG_FILE_PATH: /code/config
|
||||
API_KEY: xxxyyy
|
||||
cpu_shares: 5
|
||||
|
||||
In a **docker-compose.yml** we define the concrete services which use the
|
||||
common configuration:
|
||||
|
||||
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
|
||||
|
||||
## Adding and overriding configuration
|
||||
|
||||
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 *replaces* or *extends* the original value.
|
||||
|
||||
For single-value options like `image`, `command` or `mem_limit`, the new value
|
||||
replaces the old value.
|
||||
|
||||
# original service
|
||||
command: python app.py
|
||||
|
||||
# local service
|
||||
command: python otherapp.py
|
||||
|
||||
# result
|
||||
command: python otherapp.py
|
||||
|
||||
> **Note:** In the case of `build` and `image`, when using
|
||||
> [version 1 of the Compose file format](compose-file.md#version-1), using one
|
||||
> option in the local service causes Compose to discard the other option if it
|
||||
> was defined in the original service.
|
||||
>
|
||||
> For example, if the original service defines `image: webapp` and the
|
||||
> local service defines `build: .` then the resulting service will have
|
||||
> `build: .` and no `image` option.
|
||||
>
|
||||
> This is because `build` and `image` cannot be used together in a version 1
|
||||
> file.
|
||||
|
||||
For the **multi-value options** `ports`, `expose`, `external_links`, `dns`,
|
||||
`dns_search`, and `tmpfs`, Compose concatenates both sets of values:
|
||||
|
||||
# original service
|
||||
expose:
|
||||
- "3000"
|
||||
|
||||
# local service
|
||||
expose:
|
||||
- "4000"
|
||||
- "5000"
|
||||
|
||||
# result
|
||||
expose:
|
||||
- "3000"
|
||||
- "4000"
|
||||
- "5000"
|
||||
|
||||
In the case of `environment`, `labels`, `volumes` and `devices`, Compose
|
||||
"merges" entries together with locally-defined values taking precedence:
|
||||
|
||||
# original service
|
||||
environment:
|
||||
- FOO=original
|
||||
- BAR=original
|
||||
|
||||
# local service
|
||||
environment:
|
||||
- BAR=local
|
||||
- BAZ=local
|
||||
|
||||
# result
|
||||
environment:
|
||||
- FOO=original
|
||||
- BAR=local
|
||||
- BAZ=local
|
||||
|
||||
|
||||
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [User guide](index.md)
|
||||
- [Installing Compose](install.md)
|
||||
- [Getting Started](gettingstarted.md)
|
||||
- [Get started with Django](django.md)
|
||||
- [Get started with Rails](rails.md)
|
||||
- [Get started with WordPress](wordpress.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
128
docs/faq.md
128
docs/faq.md
|
@ -1,128 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Frequently Asked Questions"
|
||||
description = "Docker Compose FAQ"
|
||||
keywords = "documentation, docs, docker, compose, faq"
|
||||
[menu.main]
|
||||
identifier="faq.compose"
|
||||
parent="workw_compose"
|
||||
weight=90
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# Frequently asked questions
|
||||
|
||||
If you don’t see your question here, feel free to drop by `#docker-compose` on
|
||||
freenode IRC and ask the community.
|
||||
|
||||
|
||||
## Can I control service startup order?
|
||||
|
||||
Yes - see [Controlling startup order](startup-order.md).
|
||||
|
||||
|
||||
## Why do my services take 10 seconds to recreate or stop?
|
||||
|
||||
Compose stop attempts to stop a container by sending a `SIGTERM`. It then waits
|
||||
for a [default timeout of 10 seconds](./reference/stop.md). After the timeout,
|
||||
a `SIGKILL` is sent to the container to forcefully kill it. If you
|
||||
are waiting for this timeout, it means that your containers aren't shutting down
|
||||
when they receive the `SIGTERM` signal.
|
||||
|
||||
There has already been a lot written about this problem of
|
||||
[processes handling signals](https://medium.com/@gchudnov/trapping-signals-in-docker-containers-7a57fdda7d86)
|
||||
in containers.
|
||||
|
||||
To fix this problem, try the following:
|
||||
|
||||
* Make sure you're using the JSON form of `CMD` and `ENTRYPOINT`
|
||||
in your Dockerfile.
|
||||
|
||||
For example use `["program", "arg1", "arg2"]` not `"program arg1 arg2"`.
|
||||
Using the string form causes Docker to run your process using `bash` which
|
||||
doesn't handle signals properly. Compose always uses the JSON form, so don't
|
||||
worry if you override the command or entrypoint in your Compose file.
|
||||
|
||||
* If you are able, modify the application that you're running to
|
||||
add an explicit signal handler for `SIGTERM`.
|
||||
|
||||
* Set the `stop_signal` to a signal which the application knows how to handle:
|
||||
|
||||
web:
|
||||
build: .
|
||||
stop_signal: SIGINT
|
||||
|
||||
* If you can't modify the application, wrap the application in a lightweight init
|
||||
system (like [s6](http://skarnet.org/software/s6/)) or a signal proxy (like
|
||||
[dumb-init](https://github.com/Yelp/dumb-init) or
|
||||
[tini](https://github.com/krallin/tini)). Either of these wrappers take care of
|
||||
handling `SIGTERM` properly.
|
||||
|
||||
## How do I run multiple copies of a Compose file on the same host?
|
||||
|
||||
Compose uses the project name to create unique identifiers for all of a
|
||||
project's containers and other resources. To run multiple copies of a project,
|
||||
set a custom project name using the [`-p` command line
|
||||
option](./reference/overview.md) or the [`COMPOSE_PROJECT_NAME`
|
||||
environment variable](./reference/envvars.md#compose-project-name).
|
||||
|
||||
## What's the difference between `up`, `run`, and `start`?
|
||||
|
||||
Typically, you want `docker-compose up`. Use `up` to start or restart all the
|
||||
services defined in a `docker-compose.yml`. In the default "attached"
|
||||
mode, you'll see all the logs from all the containers. In "detached" mode (`-d`),
|
||||
Compose exits after starting the containers, but the containers continue to run
|
||||
in the background.
|
||||
|
||||
The `docker-compose run` command is for running "one-off" or "adhoc" tasks. It
|
||||
requires the service name you want to run and only starts containers for services
|
||||
that the running service depends on. Use `run` to run tests or perform
|
||||
an administrative task such as removing or adding data to a data volume
|
||||
container. The `run` command acts like `docker run -ti` 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.
|
||||
|
||||
The `docker-compose start` command is useful only to restart containers
|
||||
that were previously created, but were stopped. It never creates new
|
||||
containers.
|
||||
|
||||
## Can I use json instead of yaml for my Compose file?
|
||||
|
||||
Yes. [Yaml is a superset of json](http://stackoverflow.com/a/1729545/444646) so
|
||||
any JSON file should be valid Yaml. To use a JSON file with Compose,
|
||||
specify the filename to use, for example:
|
||||
|
||||
```bash
|
||||
docker-compose -f docker-compose.json up
|
||||
```
|
||||
|
||||
## Should I include my code with `COPY`/`ADD` or a volume?
|
||||
|
||||
You can add your code to the image using `COPY` or `ADD` directive in a
|
||||
`Dockerfile`. This is useful if you need to relocate your code along with the
|
||||
Docker image, for example when you're sending code to another environment
|
||||
(production, CI, etc).
|
||||
|
||||
You should use a `volume` if you want to make changes to your code and see them
|
||||
reflected immediately, for example when you're developing code and your server
|
||||
supports hot code reloading or live-reload.
|
||||
|
||||
There may be cases where you'll want to use both. You can have the image
|
||||
include the code using a `COPY`, and use a `volume` in your Compose file to
|
||||
include the code from the host during development. The volume overrides
|
||||
the directory contents of the image.
|
||||
|
||||
## Where can I find example compose files?
|
||||
|
||||
There are [many examples of Compose files on
|
||||
github](https://github.com/search?q=in%3Apath+docker-compose.yml+extension%3Ayml&type=Code).
|
||||
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [Get started with Django](django.md)
|
||||
- [Get started with Rails](rails.md)
|
||||
- [Get started with WordPress](wordpress.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
|
@ -1,191 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Getting Started"
|
||||
description = "Getting started with Docker Compose"
|
||||
keywords = ["documentation, docs, docker, compose, orchestration, containers"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=-85
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Getting Started
|
||||
|
||||
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're not familiar with it.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Make sure you have already
|
||||
[installed both Docker Engine and Docker Compose](install.md). You
|
||||
don't need to install Python, it is provided by a Docker image.
|
||||
|
||||
## Step 1: Setup
|
||||
|
||||
1. Create a directory for the project:
|
||||
|
||||
$ mkdir composetest
|
||||
$ cd composetest
|
||||
|
||||
2. With your favorite text editor create a file called `app.py` in your project
|
||||
directory.
|
||||
|
||||
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__ == "__main__":
|
||||
app.run(host="0.0.0.0", debug=True)
|
||||
|
||||
3. Create another file called `requirements.txt` in your project directory and
|
||||
add the following:
|
||||
|
||||
flask
|
||||
redis
|
||||
|
||||
These define the applications dependencies.
|
||||
|
||||
## Step 2: Create a Docker image
|
||||
|
||||
In this step, you build a new Docker image. The image contains all the
|
||||
dependencies the Python application requires, including Python itself.
|
||||
|
||||
1. In your project directory create a file named `Dockerfile` and add the
|
||||
following:
|
||||
|
||||
FROM python:2.7
|
||||
ADD . /code
|
||||
WORKDIR /code
|
||||
RUN pip install -r requirements.txt
|
||||
CMD python app.py
|
||||
|
||||
This tells Docker to:
|
||||
|
||||
* Build an image starting with the Python 2.7 image.
|
||||
* Add the current directory `.` into the path `/code` in the image.
|
||||
* Set the working directory to `/code`.
|
||||
* Install the Python dependencies.
|
||||
* Set the default command for the container to `python app.py`
|
||||
|
||||
For more information on how to write Dockerfiles, see the [Docker user guide](/engine/tutorials/dockerimages.md#building-an-image-from-a-dockerfile) and the [Dockerfile reference](/engine/reference/builder.md).
|
||||
|
||||
2. Build the image.
|
||||
|
||||
$ docker build -t web .
|
||||
|
||||
This command builds an image named `web` from the contents of the current
|
||||
directory. The command automatically locates the `Dockerfile`, `app.py`, and
|
||||
`requirements.txt` files.
|
||||
|
||||
|
||||
## Step 3: Define services
|
||||
|
||||
Define a set of services using `docker-compose.yml`:
|
||||
|
||||
1. Create a file called docker-compose.yml in your project directory and add
|
||||
the following:
|
||||
|
||||
|
||||
version: '2'
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- .:/code
|
||||
depends_on:
|
||||
- redis
|
||||
redis:
|
||||
image: redis
|
||||
|
||||
This Compose file defines two services, `web` and `redis`. The web service:
|
||||
|
||||
* Builds from the `Dockerfile` in the current directory.
|
||||
* Forwards the exposed port 5000 on the container to port 5000 on the host machine.
|
||||
* Mounts the project directory on the host to `/code` inside the container allowing you to modify the code without having to rebuild the image.
|
||||
* Links the web service to the Redis service.
|
||||
|
||||
The `redis` service uses the latest public [Redis](https://registry.hub.docker.com/_/redis/) image pulled from the Docker Hub registry.
|
||||
|
||||
## Step 4: Build and run your app with Compose
|
||||
|
||||
1. From your project directory, start up your application.
|
||||
|
||||
$ 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
|
||||
|
||||
Compose pulls a Redis image, builds an image for your code, and start the
|
||||
services you defined.
|
||||
|
||||
2. Enter `http://0.0.0.0:5000/` in a browser to see the application running.
|
||||
|
||||
If you're using Docker on Linux natively, then the web app should now be
|
||||
listening on port 5000 on your Docker daemon host. If `http://0.0.0.0:5000`
|
||||
doesn't resolve, you can also try `http://localhost:5000`.
|
||||
|
||||
If you're using Docker Machine on a Mac, use `docker-machine ip MACHINE_VM` to get
|
||||
the IP address of your Docker host. Then, `open http://MACHINE_VM_IP:5000` in a
|
||||
browser.
|
||||
|
||||
You should see a message in your browser saying:
|
||||
|
||||
`Hello World! I have been seen 1 times.`
|
||||
|
||||
3. Refresh the page.
|
||||
|
||||
The number should increment.
|
||||
|
||||
## Step 5: Experiment with some other commands
|
||||
|
||||
If you want to run your services in the background, you can pass the `-d` flag
|
||||
(for "detached" mode) to `docker-compose up` and use `docker-compose ps` to
|
||||
see what is currently running:
|
||||
|
||||
$ 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->5000/tcp
|
||||
|
||||
The `docker-compose run` command allows you to run one-off commands for your
|
||||
services. For example, to see what environment variables are available to the
|
||||
`web` service:
|
||||
|
||||
$ docker-compose run web env
|
||||
|
||||
See `docker-compose --help` to see other available commands. You can also install [command completion](completion.md) for the bash and zsh shell, which will also show you available commands.
|
||||
|
||||
If you started Compose with `docker-compose up -d`, you'll probably want to stop
|
||||
your services once you've finished with them:
|
||||
|
||||
$ docker-compose stop
|
||||
|
||||
At this point, you have seen the basics of how Compose works.
|
||||
|
||||
|
||||
## Where to go next
|
||||
|
||||
- Next, try the quick start guide for [Django](django.md),
|
||||
[Rails](rails.md), or [WordPress](wordpress.md).
|
||||
- [Explore the full list of Compose commands](./reference/index.md)
|
||||
- [Compose configuration file reference](compose-file.md)
|
Binary file not shown.
Before Width: | Height: | Size: 28 KiB |
Binary file not shown.
Before Width: | Height: | Size: 69 KiB |
Binary file not shown.
Before Width: | Height: | Size: 69 KiB |
Binary file not shown.
Before Width: | Height: | Size: 29 KiB |
Binary file not shown.
Before Width: | Height: | Size: 61 KiB |
|
@ -1,30 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Docker Compose"
|
||||
description = "Introduction and Overview of Compose"
|
||||
keywords = ["documentation, docs, docker, compose, orchestration, containers"]
|
||||
[menu.main]
|
||||
identifier="workw_compose"
|
||||
weight=-70
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Docker Compose
|
||||
|
||||
Compose is a tool for defining and running multi-container Docker applications. To learn more about Compose refer to the following documentation:
|
||||
|
||||
- [Compose Overview](overview.md)
|
||||
- [Install Compose](install.md)
|
||||
- [Getting Started](gettingstarted.md)
|
||||
- [Get started with Django](django.md)
|
||||
- [Get started with Rails](rails.md)
|
||||
- [Get started with WordPress](wordpress.md)
|
||||
- [Frequently asked questions](faq.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
||||
- [Environment file](env-file.md)
|
||||
|
||||
To see a detailed list of changes for past and current releases of Docker
|
||||
Compose, please refer to the
|
||||
[CHANGELOG](https://github.com/docker/compose/blob/master/CHANGELOG.md).
|
136
docs/install.md
136
docs/install.md
|
@ -1,136 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Install Compose"
|
||||
description = "How to install Docker Compose"
|
||||
keywords = ["compose, orchestration, install, installation, docker, documentation"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=-90
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Install Docker Compose
|
||||
|
||||
You can run Compose on OS X, Windows and 64-bit Linux. To install it, you'll need to install Docker first.
|
||||
|
||||
To install Compose, do the following:
|
||||
|
||||
1. Install Docker Engine:
|
||||
|
||||
* <a href="/engine/installation/mac/" target="_blank">Mac OS X installation</a>
|
||||
|
||||
* <a href="/engine/installation/windows/" target="_blank">Windows installation</a>
|
||||
|
||||
* <a href="/engine/installation/ubuntulinux/" target="_blank">Ubuntu installation</a>
|
||||
|
||||
* <a href="/engine/installation/" target="_blank">other system installations</a>
|
||||
|
||||
2. The Docker Toolbox installation includes both Engine and Compose, so Mac and Windows users are done installing. Others should continue to the next step.
|
||||
|
||||
3. Go to the <a href="https://github.com/docker/compose/releases" target="_blank">Compose repository release page on GitHub</a>.
|
||||
|
||||
4. Follow the instructions from the release page and run the `curl` command,
|
||||
which the release page specifies, in your terminal.
|
||||
|
||||
> Note: If you get a "Permission denied" error, your `/usr/local/bin` directory
|
||||
probably isn't writable and you'll need to install Compose as the superuser. Run
|
||||
`sudo -i`, then the two commands below, then `exit`.
|
||||
|
||||
The following is an example command illustrating the format:
|
||||
|
||||
curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
|
||||
|
||||
If you have problems installing with `curl`, see
|
||||
[Alternative Install Options](#alternative-install-options).
|
||||
|
||||
5. Apply executable permissions to the binary:
|
||||
|
||||
$ chmod +x /usr/local/bin/docker-compose
|
||||
|
||||
6. Optionally, install [command completion](completion.md) for the
|
||||
`bash` and `zsh` shell.
|
||||
|
||||
7. Test the installation.
|
||||
|
||||
$ docker-compose --version
|
||||
docker-compose version: 1.8.0
|
||||
|
||||
|
||||
## Alternative install options
|
||||
|
||||
### Install using pip
|
||||
|
||||
Compose can be installed from [pypi](https://pypi.python.org/pypi/docker-compose)
|
||||
using `pip`. If you install using `pip` it is highly recommended that you use a
|
||||
[virtualenv](https://virtualenv.pypa.io/en/latest/) because many operating systems
|
||||
have python system packages that conflict with docker-compose dependencies. See
|
||||
the [virtualenv tutorial](http://docs.python-guide.org/en/latest/dev/virtualenvs/)
|
||||
to get started.
|
||||
|
||||
$ pip install docker-compose
|
||||
|
||||
> **Note:** pip version 6.0 or greater is required
|
||||
|
||||
### Install as a container
|
||||
|
||||
Compose can also be run inside a container, from a small bash script wrapper.
|
||||
To install compose as a container run:
|
||||
|
||||
$ curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose
|
||||
$ chmod +x /usr/local/bin/docker-compose
|
||||
|
||||
## Master builds
|
||||
|
||||
If you're interested in trying out a pre-release build you can download a
|
||||
binary from https://dl.bintray.com/docker-compose/master/. Pre-release
|
||||
builds allow you to try out new features before they are released, but may
|
||||
be less stable.
|
||||
|
||||
|
||||
## Upgrading
|
||||
|
||||
If you're upgrading from Compose 1.2 or earlier, you'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.
|
||||
|
||||
If Compose detects containers that were created without labels, it will refuse
|
||||
to run so that you don'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:
|
||||
|
||||
$ docker-compose migrate-to-labels
|
||||
|
||||
Alternatively, if you're not worried about keeping them, you can remove them.
|
||||
Compose will just create new ones.
|
||||
|
||||
$ docker rm -f -v myapp_web_1 myapp_db_1 ...
|
||||
|
||||
|
||||
## Uninstallation
|
||||
|
||||
To uninstall Docker Compose if you installed using `curl`:
|
||||
|
||||
$ rm /usr/local/bin/docker-compose
|
||||
|
||||
|
||||
To uninstall Docker Compose if you installed using `pip`:
|
||||
|
||||
$ pip uninstall docker-compose
|
||||
|
||||
>**Note**: If you get a "Permission denied" error using either of the above
|
||||
>methods, you probably do not have the proper permissions to remove
|
||||
>`docker-compose`. To force the removal, prepend `sudo` to either of the above
|
||||
>commands and run again.
|
||||
|
||||
|
||||
## Where to go next
|
||||
|
||||
- [User guide](index.md)
|
||||
- [Getting Started](gettingstarted.md)
|
||||
- [Get started with Django](django.md)
|
||||
- [Get started with Rails](rails.md)
|
||||
- [Get started with WordPress](wordpress.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
|
@ -1,48 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Link Environment Variables"
|
||||
description = "Compose CLI reference"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, reference"]
|
||||
aliases = ["/compose/env"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=89
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# Link environment variables reference
|
||||
|
||||
> **Note:** 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 [docker-compose.yml documentation](compose-file.md#links) for details.
|
||||
>
|
||||
> Environment variables will only be populated if you're using the [legacy version 1 Compose file format](compose-file.md#versioning).
|
||||
|
||||
Compose uses [Docker links](/engine/userguide/networking/default_network/dockerlinks.md)
|
||||
to expose services' containers to one another. Each linked container injects a set of
|
||||
environment variables, each of which begins with the uppercase name of the container.
|
||||
|
||||
To see what environment variables are available to a service, run `docker-compose run SERVICE env`.
|
||||
|
||||
<b><i>name</i>\_PORT</b><br>
|
||||
Full URL, e.g. `DB_PORT=tcp://172.17.0.5:5432`
|
||||
|
||||
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i></b><br>
|
||||
Full URL, e.g. `DB_PORT_5432_TCP=tcp://172.17.0.5:5432`
|
||||
|
||||
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i>\_ADDR</b><br>
|
||||
Container's IP address, e.g. `DB_PORT_5432_TCP_ADDR=172.17.0.5`
|
||||
|
||||
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i>\_PORT</b><br>
|
||||
Exposed port number, e.g. `DB_PORT_5432_TCP_PORT=5432`
|
||||
|
||||
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i>\_PROTO</b><br>
|
||||
Protocol (tcp or udp), e.g. `DB_PORT_5432_TCP_PROTO=tcp`
|
||||
|
||||
<b><i>name</i>\_NAME</b><br>
|
||||
Fully qualified container name, e.g. `DB_1_NAME=/myapp_web_1/myapp_db_1`
|
||||
|
||||
## Related Information
|
||||
|
||||
- [User guide](index.md)
|
||||
- [Installing Compose](install.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
|
@ -1,154 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Networking in Compose"
|
||||
description = "How Compose sets up networking between containers"
|
||||
keywords = ["documentation, docs, docker, compose, orchestration, containers, networking"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=21
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Networking in Compose
|
||||
|
||||
> **Note:** This document only applies if you're using [version 2 of the Compose file format](compose-file.md#versioning). Networking features are not supported for version 1 (legacy) Compose files.
|
||||
|
||||
By default Compose sets up a single
|
||||
[network](https://docs.docker.com/engine/reference/commandline/network_create/) for your app. Each
|
||||
container for a service joins the default network and is both *reachable* by
|
||||
other containers on that network, and *discoverable* by them at a hostname
|
||||
identical to the container name.
|
||||
|
||||
> **Note:** Your app's network is given a name based on the "project name",
|
||||
> which is based on the name of the directory it lives in. You can override the
|
||||
> project name with either the [`--project-name`
|
||||
> flag](reference/overview.md) or the [`COMPOSE_PROJECT_NAME` environment
|
||||
> variable](reference/envvars.md#compose-project-name).
|
||||
|
||||
For example, suppose your app is in a directory called `myapp`, and your `docker-compose.yml` looks like this:
|
||||
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
db:
|
||||
image: postgres
|
||||
|
||||
When you run `docker-compose up`, the following happens:
|
||||
|
||||
1. A network called `myapp_default` is created.
|
||||
2. A container is created using `web`'s configuration. It joins the network
|
||||
`myapp_default` under the name `web`.
|
||||
3. A container is created using `db`'s configuration. It joins the network
|
||||
`myapp_default` under the name `db`.
|
||||
|
||||
Each container can now look up the hostname `web` or `db` and
|
||||
get back the appropriate container's IP address. For example, `web`'s
|
||||
application code could connect to the URL `postgres://db:5432` and start
|
||||
using the Postgres database.
|
||||
|
||||
Because `web` explicitly maps a port, it's also accessible from the outside world via port 8000 on your Docker host's network interface.
|
||||
|
||||
## Updating containers
|
||||
|
||||
If you make a configuration change to a service and run `docker-compose up` 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.
|
||||
|
||||
If any containers have connections open to the old container, they will be closed. It is a container's responsibility to detect this condition, look up the name again and reconnect.
|
||||
|
||||
## Links
|
||||
|
||||
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's name. In the following example, `db` is reachable from `web` at the hostnames `db` and `database`:
|
||||
|
||||
version: '2'
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
links:
|
||||
- "db:database"
|
||||
db:
|
||||
image: postgres
|
||||
|
||||
See the [links reference](compose-file.md#links) for more information.
|
||||
|
||||
## Multi-host networking
|
||||
|
||||
When [deploying a Compose application to a Swarm cluster](swarm.md), you can make use of the built-in `overlay` driver to enable multi-host communication between containers with no changes to your Compose file or application code.
|
||||
|
||||
Consult the [Getting started with multi-host networking](https://docs.docker.com/engine/userguide/networking/get-started-overlay/) to see how to set up a Swarm cluster. The cluster will use the `overlay` driver by default, but you can specify it explicitly if you prefer - see below for how to do this.
|
||||
|
||||
## Specifying custom networks
|
||||
|
||||
Instead of just using the default app network, you can specify your own networks with the top-level `networks` key. This lets you create more complex topologies and specify [custom network drivers](https://docs.docker.com/engine/extend/plugins_network/) and options. You can also use it to connect services to externally-created networks which aren't managed by Compose.
|
||||
|
||||
Each service can specify what networks to connect to with the *service-level* `networks` key, which is a list of names referencing entries under the *top-level* `networks` key.
|
||||
|
||||
Here's an example Compose file defining two custom networks. The `proxy` service is isolated from the `db` service, because they do not share a network in common - only `app` can talk to both.
|
||||
|
||||
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: "1"
|
||||
bar: "2"
|
||||
|
||||
Networks can be configured with static IP addresses by setting the [ipv4_address and/or ipv6_address](compose-file.md#ipv4-address-ipv6-address) for each attached network.
|
||||
|
||||
For full details of the network configuration options available, see the following references:
|
||||
|
||||
- [Top-level `networks` key](compose-file.md#network-configuration-reference)
|
||||
- [Service-level `networks` key](compose-file.md#networks)
|
||||
|
||||
## Configuring the default network
|
||||
|
||||
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 `networks` named `default`:
|
||||
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
db:
|
||||
image: postgres
|
||||
|
||||
networks:
|
||||
default:
|
||||
# Use a custom driver
|
||||
driver: custom-driver-1
|
||||
|
||||
## Using a pre-existing network
|
||||
|
||||
If you want your containers to join a pre-existing network, use the [`external` option](compose-file.md#network-configuration-reference):
|
||||
|
||||
networks:
|
||||
default:
|
||||
external:
|
||||
name: my-pre-existing-network
|
||||
|
||||
Instead of attemping to create a network called `[projectname]_default`, Compose will look for a network called `my-pre-existing-network` and connect your app's containers to it.
|
188
docs/overview.md
188
docs/overview.md
|
@ -1,188 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Overview of Docker Compose"
|
||||
description = "Introduction and Overview of Compose"
|
||||
keywords = ["documentation, docs, docker, compose, orchestration, containers"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=-99
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Overview of Docker Compose
|
||||
|
||||
Compose is a tool for defining and running multi-container Docker applications.
|
||||
With Compose, you use a Compose file to configure your application'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 [the list of features](#features).
|
||||
|
||||
Compose is great for development, testing, and staging environments, as well as
|
||||
CI workflows. You can learn more about each case in
|
||||
[Common Use Cases](#common-use-cases).
|
||||
|
||||
Using Compose is basically a three-step process.
|
||||
|
||||
1. Define your app's environment with a `Dockerfile` so it can be reproduced
|
||||
anywhere.
|
||||
|
||||
2. Define the services that make up your app in `docker-compose.yml`
|
||||
so they can be run together in an isolated environment.
|
||||
|
||||
3. Lastly, run
|
||||
`docker-compose up` and Compose will start and run your entire app.
|
||||
|
||||
A `docker-compose.yml` looks like this:
|
||||
|
||||
version: '2'
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- .:/code
|
||||
- logvolume01:/var/log
|
||||
links:
|
||||
- redis
|
||||
redis:
|
||||
image: redis
|
||||
volumes:
|
||||
logvolume01: {}
|
||||
|
||||
For more information about the Compose file, see the
|
||||
[Compose file reference](compose-file.md)
|
||||
|
||||
Compose has commands for managing the whole lifecycle of your application:
|
||||
|
||||
* Start, stop and rebuild services
|
||||
* View the status of running services
|
||||
* Stream the log output of running services
|
||||
* Run a one-off command on a service
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [Getting Started](gettingstarted.md)
|
||||
- [Get started with Django](django.md)
|
||||
- [Get started with Rails](rails.md)
|
||||
- [Get started with WordPress](wordpress.md)
|
||||
- [Frequently asked questions](faq.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
||||
|
||||
## Features
|
||||
|
||||
The features of Compose that make it effective are:
|
||||
|
||||
* [Multiple isolated environments on a single host](#Multiple-isolated-environments-on-a-single-host)
|
||||
* [Preserve volume data when containers are created](#preserve-volume-data-when-containers-are-created)
|
||||
* [Only recreate containers that have changed](#only-recreate-containers-that-have-changed)
|
||||
* [Variables and moving a composition between environments](#variables-and-moving-a-composition-between-environments)
|
||||
|
||||
### Multiple isolated environments on a single host
|
||||
|
||||
Compose uses a project name to isolate environments from each other. You can make use of this project name in several different contexts:
|
||||
|
||||
* 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)
|
||||
* on a CI server, to keep builds from interfering with each other, you can set
|
||||
the project name to a unique build number
|
||||
* on a shared host or dev host, to prevent different projects, which may use the
|
||||
same service names, from interfering with each other
|
||||
|
||||
The default project name is the basename of the project directory. You can set
|
||||
a custom project name by using the
|
||||
[`-p` command line option](./reference/overview.md) or the
|
||||
[`COMPOSE_PROJECT_NAME` environment variable](./reference/envvars.md#compose-project-name).
|
||||
|
||||
### Preserve volume data when containers are created
|
||||
|
||||
Compose preserves all volumes used by your services. When `docker-compose up`
|
||||
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've created in volumes isn't lost.
|
||||
|
||||
|
||||
### Only recreate containers that have changed
|
||||
|
||||
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.
|
||||
|
||||
|
||||
### Variables and moving a composition between environments
|
||||
|
||||
Compose supports variables in the Compose file. You can use these variables
|
||||
to customize your composition for different environments, or different users.
|
||||
See [Variable substitution](compose-file.md#variable-substitution) for more
|
||||
details.
|
||||
|
||||
You can extend a Compose file using the `extends` field or by creating multiple
|
||||
Compose files. See [extends](extends.md) for more details.
|
||||
|
||||
|
||||
## Common Use Cases
|
||||
|
||||
Compose can be used in many different ways. Some common use cases are outlined
|
||||
below.
|
||||
|
||||
### Development environments
|
||||
|
||||
When you'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.
|
||||
|
||||
The [Compose file](compose-file.md) provides a way to document and configure
|
||||
all of the application'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
|
||||
(`docker-compose up`).
|
||||
|
||||
Together, these features provide a convenient way for developers to get
|
||||
started on a project. Compose can reduce a multi-page "developer getting
|
||||
started guide" to a single machine readable Compose file and a few commands.
|
||||
|
||||
### Automated testing environments
|
||||
|
||||
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 [Compose file](compose-file.md) you can create and destroy these environments in just a few commands:
|
||||
|
||||
$ docker-compose up -d
|
||||
$ ./run_tests
|
||||
$ docker-compose down
|
||||
|
||||
### Single host deployments
|
||||
|
||||
Compose has traditionally been focused on development and testing workflows,
|
||||
but with each release we'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
|
||||
[Docker Machine](/machine/overview.md) or an entire
|
||||
[Docker Swarm](/swarm/overview.md) cluster.
|
||||
|
||||
For details on using production-oriented features, see
|
||||
[compose in production](production.md) in this documentation.
|
||||
|
||||
|
||||
## Release Notes
|
||||
|
||||
To see a detailed list of changes for past and current releases of Docker
|
||||
Compose, please refer to the
|
||||
[CHANGELOG](https://github.com/docker/compose/blob/master/CHANGELOG.md).
|
||||
|
||||
## Getting help
|
||||
|
||||
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.
|
||||
|
||||
* To report bugs or file feature requests: please use the [issue tracker on Github](https://github.com/docker/compose/issues).
|
||||
|
||||
* To talk about the project with people in real time: please join the
|
||||
`#docker-compose` channel on freenode IRC.
|
||||
|
||||
* To contribute code or documentation changes: please submit a [pull request on Github](https://github.com/docker/compose/pulls).
|
||||
|
||||
For more information and resources, please visit the [Getting Help project page](https://docs.docker.com/opensource/get-help/).
|
|
@ -1,88 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Using Compose in Production"
|
||||
description = "Guide to using Docker Compose in production"
|
||||
keywords = ["documentation, docs, docker, compose, orchestration, containers, production"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=22
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
## Using Compose in production
|
||||
|
||||
When you define your app with Compose in development, you can use this
|
||||
definition to run your application in different environments such as CI,
|
||||
staging, and production.
|
||||
|
||||
The easiest way to deploy an application is to run it on a single server,
|
||||
similar to how you would run your development environment. If you want to scale
|
||||
up your application, you can run Compose apps on a Swarm cluster.
|
||||
|
||||
### Modify your Compose file for production
|
||||
|
||||
You'll almost certainly want to make changes to your app configuration that are
|
||||
more appropriate to a live environment. These changes may include:
|
||||
|
||||
- Removing any volume bindings for application code, so that code stays inside
|
||||
the container and can't be changed from outside
|
||||
- Binding to different ports on the host
|
||||
- Setting environment variables differently (e.g., to decrease the verbosity of
|
||||
logging, or to enable email sending)
|
||||
- Specifying a restart policy (e.g., `restart: always`) to avoid downtime
|
||||
- Adding extra services (e.g., a log aggregator)
|
||||
|
||||
For this reason, you'll probably want to define an additional Compose file, say
|
||||
`production.yml`, which specifies production-appropriate
|
||||
configuration. This configuration file only needs to include the changes you'd
|
||||
like to make from the original Compose file. The additional Compose file
|
||||
can be applied over the original `docker-compose.yml` to create a new configuration.
|
||||
|
||||
Once you've got a second configuration file, tell Compose to use it with the
|
||||
`-f` option:
|
||||
|
||||
$ docker-compose -f docker-compose.yml -f production.yml up -d
|
||||
|
||||
See [Using multiple compose files](extends.md#different-environments) for a more
|
||||
complete example.
|
||||
|
||||
### Deploying changes
|
||||
|
||||
When you make changes to your app code, you'll need to rebuild your image and
|
||||
recreate your app's containers. To redeploy a service called
|
||||
`web`, you would use:
|
||||
|
||||
$ docker-compose build web
|
||||
$ docker-compose up --no-deps -d web
|
||||
|
||||
This will first rebuild the image for `web` and then stop, destroy, and recreate
|
||||
*just* the `web` service. The `--no-deps` flag prevents Compose from also
|
||||
recreating any services which `web` depends on.
|
||||
|
||||
### Running Compose on a single server
|
||||
|
||||
You can use Compose to deploy an app to a remote Docker host by setting the
|
||||
`DOCKER_HOST`, `DOCKER_TLS_VERIFY`, and `DOCKER_CERT_PATH` environment variables
|
||||
appropriately. For tasks like this,
|
||||
[Docker Machine](/machine/overview.md) makes managing local and
|
||||
remote Docker hosts very easy, and is recommended even if you're not deploying
|
||||
remotely.
|
||||
|
||||
Once you've set up your environment variables, all the normal `docker-compose`
|
||||
commands will work with no further configuration.
|
||||
|
||||
### Running Compose on a Swarm cluster
|
||||
|
||||
[Docker Swarm](/swarm/overview.md), a Docker-native clustering
|
||||
system, exposes the same API as a single Docker host, which means you can use
|
||||
Compose against a Swarm instance and run your apps across multiple hosts.
|
||||
|
||||
Read more about the Compose/Swarm integration in the
|
||||
[integration guide](swarm.md).
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
174
docs/rails.md
174
docs/rails.md
|
@ -1,174 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Quickstart: Compose and Rails"
|
||||
description = "Getting started with Docker Compose and Rails"
|
||||
keywords = ["documentation, docs, docker, compose, orchestration, containers"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=5
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
## Quickstart: Docker Compose and Rails
|
||||
|
||||
This Quickstart guide will show you how to use Docker Compose to set up and run a Rails/PostgreSQL app. Before starting, you'll need to have [Compose installed](install.md).
|
||||
|
||||
### Define the project
|
||||
|
||||
Start by setting up the three files you'll need to build the app. First, since
|
||||
your app is going to run inside a Docker container containing all of its
|
||||
dependencies, you'll need to define exactly what needs to be included in the
|
||||
container. This is done using a file called `Dockerfile`. To begin with, the
|
||||
Dockerfile consists of:
|
||||
|
||||
FROM ruby:2.2.0
|
||||
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
|
||||
RUN mkdir /myapp
|
||||
WORKDIR /myapp
|
||||
ADD Gemfile /myapp/Gemfile
|
||||
ADD Gemfile.lock /myapp/Gemfile.lock
|
||||
RUN bundle install
|
||||
ADD . /myapp
|
||||
|
||||
That'll put your application code inside an image that will build a container
|
||||
with Ruby, Bundler and all your dependencies inside it. For more information on
|
||||
how to write Dockerfiles, see the [Docker user guide](/engine/tutorials/dockerimages.md#building-an-image-from-a-dockerfile) and the [Dockerfile reference](/engine/reference/builder.md).
|
||||
|
||||
Next, create a bootstrap `Gemfile` which just loads Rails. It'll be overwritten in a moment by `rails new`.
|
||||
|
||||
source 'https://rubygems.org'
|
||||
gem 'rails', '4.2.0'
|
||||
|
||||
You'll need an empty `Gemfile.lock` in order to build our `Dockerfile`.
|
||||
|
||||
$ touch Gemfile.lock
|
||||
|
||||
Finally, `docker-compose.yml` is where the magic happens. This file describes
|
||||
the services that comprise your app (a database and a web app), how to get each
|
||||
one's Docker image (the database just runs on a pre-made PostgreSQL image, and
|
||||
the web app is built from the current directory), and the configuration needed
|
||||
to link them together and expose the web app's port.
|
||||
|
||||
version: '2'
|
||||
services:
|
||||
db:
|
||||
image: postgres
|
||||
web:
|
||||
build: .
|
||||
command: bundle exec rails s -p 3000 -b '0.0.0.0'
|
||||
volumes:
|
||||
- .:/myapp
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
### Build the project
|
||||
|
||||
With those three files in place, you can now generate the Rails skeleton app
|
||||
using `docker-compose run`:
|
||||
|
||||
$ docker-compose run web rails new . --force --database=postgresql --skip-bundle
|
||||
|
||||
First, Compose will build the image for the `web` service using the `Dockerfile`. Then it'll run `rails new` inside a new container, using that image. Once it's done, you should have generated a fresh app:
|
||||
|
||||
$ ls -l
|
||||
total 56
|
||||
-rw-r--r-- 1 user staff 215 Feb 13 23:33 Dockerfile
|
||||
-rw-r--r-- 1 user staff 1480 Feb 13 23:43 Gemfile
|
||||
-rw-r--r-- 1 user staff 2535 Feb 13 23:43 Gemfile.lock
|
||||
-rw-r--r-- 1 root root 478 Feb 13 23:43 README.rdoc
|
||||
-rw-r--r-- 1 root root 249 Feb 13 23:43 Rakefile
|
||||
drwxr-xr-x 8 root root 272 Feb 13 23:43 app
|
||||
drwxr-xr-x 6 root root 204 Feb 13 23:43 bin
|
||||
drwxr-xr-x 11 root root 374 Feb 13 23:43 config
|
||||
-rw-r--r-- 1 root root 153 Feb 13 23:43 config.ru
|
||||
drwxr-xr-x 3 root root 102 Feb 13 23:43 db
|
||||
-rw-r--r-- 1 user staff 161 Feb 13 23:35 docker-compose.yml
|
||||
drwxr-xr-x 4 root root 136 Feb 13 23:43 lib
|
||||
drwxr-xr-x 3 root root 102 Feb 13 23:43 log
|
||||
drwxr-xr-x 7 root root 238 Feb 13 23:43 public
|
||||
drwxr-xr-x 9 root root 306 Feb 13 23:43 test
|
||||
drwxr-xr-x 3 root root 102 Feb 13 23:43 tmp
|
||||
drwxr-xr-x 3 root root 102 Feb 13 23:43 vendor
|
||||
|
||||
|
||||
If you are running Docker on Linux, the files `rails new` created are owned by
|
||||
root. This happens because the container runs as the root user. Change the
|
||||
ownership of the the new files.
|
||||
|
||||
sudo chown -R $USER:$USER .
|
||||
|
||||
If you are running Docker on Mac or Windows, you should already have ownership
|
||||
of all files, including those generated by `rails new`. List the files just to
|
||||
verify this.
|
||||
|
||||
Uncomment the line in your new `Gemfile` which loads `therubyracer`, so you've
|
||||
got a Javascript runtime:
|
||||
|
||||
gem 'therubyracer', platforms: :ruby
|
||||
|
||||
Now that you've got a new `Gemfile`, you need to build the image again. (This,
|
||||
and changes to the Dockerfile itself, should be the only times you'll need to
|
||||
rebuild.)
|
||||
|
||||
$ docker-compose build
|
||||
|
||||
|
||||
### Connect the database
|
||||
|
||||
The app is now bootable, but you're not quite there yet. By default, Rails
|
||||
expects a database to be running on `localhost` - so you need to point it at the
|
||||
`db` container instead. You also need to change the database and username to
|
||||
align with the defaults set by the `postgres` image.
|
||||
|
||||
Replace the contents of `config/database.yml` with the following:
|
||||
|
||||
development: &default
|
||||
adapter: postgresql
|
||||
encoding: unicode
|
||||
database: postgres
|
||||
pool: 5
|
||||
username: postgres
|
||||
password:
|
||||
host: db
|
||||
|
||||
test:
|
||||
<<: *default
|
||||
database: myapp_test
|
||||
|
||||
You can now boot the app with:
|
||||
|
||||
$ docker-compose up
|
||||
|
||||
If all's well, you should see some PostgreSQL output, and then—after a few
|
||||
seconds—the familiar refrain:
|
||||
|
||||
myapp_web_1 | [2014-01-17 17:16:29] INFO WEBrick 1.3.1
|
||||
myapp_web_1 | [2014-01-17 17:16:29] INFO ruby 2.2.0 (2014-12-25) [x86_64-linux-gnu]
|
||||
myapp_web_1 | [2014-01-17 17:16:29] INFO WEBrick::HTTPServer#start: pid=1 port=3000
|
||||
|
||||
Finally, you need to create the database. In another terminal, run:
|
||||
|
||||
$ docker-compose run web rake db:create
|
||||
|
||||
That's it. Your app should now be running on port 3000 on your Docker daemon. If you're using [Docker Machine](/machine/overview.md), then `docker-machine ip MACHINE_VM` returns the Docker host IP address.
|
||||
|
||||

|
||||
|
||||
>**Note**: If you stop the example application and attempt to restart it, you might get the
|
||||
following error: `web_1 | A server is already running. Check
|
||||
/myapp/tmp/pids/server.pid.` One way to resolve this is to delete the file
|
||||
`tmp/pids/server.pid`, and then re-start the application with `docker-compose
|
||||
up`.
|
||||
|
||||
|
||||
## More Compose documentation
|
||||
|
||||
- [User guide](index.md)
|
||||
- [Installing Compose](install.md)
|
||||
- [Getting Started](gettingstarted.md)
|
||||
- [Get started with Django](django.md)
|
||||
- [Get started with WordPress](wordpress.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
|
@ -1,25 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "build"
|
||||
description = "build"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, build"]
|
||||
[menu.main]
|
||||
identifier="build.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# build
|
||||
|
||||
```
|
||||
Usage: build [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
--force-rm Always remove intermediate containers.
|
||||
--no-cache Do not use cache when building the image.
|
||||
--pull Always attempt to pull a newer version of the image.
|
||||
```
|
||||
|
||||
Services are built once and then tagged as `project_service`, e.g.,
|
||||
`composetest_db`. If you change a service's Dockerfile or the contents of its
|
||||
build directory, run `docker-compose build` to rebuild it.
|
|
@ -1,31 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "bundle"
|
||||
description = "Create a distributed application bundle from the Compose file."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, bundle"]
|
||||
[menu.main]
|
||||
identifier="bundle.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# bundle
|
||||
|
||||
```
|
||||
Usage: bundle [options]
|
||||
|
||||
Options:
|
||||
--push-images Automatically push images for any services
|
||||
which have a `build` option specified.
|
||||
|
||||
-o, --output PATH Path to write the bundle file to.
|
||||
Defaults to "<project name>.dab".
|
||||
```
|
||||
|
||||
Generate a Distributed Application Bundle (DAB) from the Compose file.
|
||||
|
||||
Images must have digests stored, which requires interaction with a
|
||||
Docker registry. If digests aren't stored for all images, you can fetch
|
||||
them with `docker-compose pull` or `docker-compose push`. To push images
|
||||
automatically when bundling, pass `--push-images`. Only services with
|
||||
a `build` option specified will have their images pushed.
|
|
@ -1,23 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "config"
|
||||
description = "Config validates and view the compose file."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, config"]
|
||||
[menu.main]
|
||||
identifier="config.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# config
|
||||
|
||||
```:
|
||||
Usage: config [options]
|
||||
|
||||
Options:
|
||||
-q, --quiet Only validate the configuration, don't print
|
||||
anything.
|
||||
--services Print the service names, one per line.
|
||||
```
|
||||
|
||||
Validate and view the compose file.
|
|
@ -1,26 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "create"
|
||||
description = "Create creates containers for a service."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, create"]
|
||||
[menu.main]
|
||||
identifier="create.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# create
|
||||
|
||||
```
|
||||
Creates containers for a service.
|
||||
|
||||
Usage: create [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
--force-recreate Recreate containers even if their configuration and
|
||||
image haven't changed. Incompatible with --no-recreate.
|
||||
--no-recreate If containers already exist, don't recreate them.
|
||||
Incompatible with --force-recreate.
|
||||
--no-build Don't build an image, even if it's missing.
|
||||
--build Build images before creating containers.
|
||||
```
|
|
@ -1,38 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "down"
|
||||
description = "down"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, down"]
|
||||
[menu.main]
|
||||
identifier="down.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# down
|
||||
|
||||
```
|
||||
Usage: down [options]
|
||||
|
||||
Options:
|
||||
--rmi type Remove images. Type must be one of:
|
||||
'all': Remove all images used by any service.
|
||||
'local': Remove only images that don't have a custom tag
|
||||
set by the `image` field.
|
||||
-v, --volumes Remove named volumes declared in the `volumes` section
|
||||
of the Compose file and anonymous volumes
|
||||
attached to containers.
|
||||
--remove-orphans Remove containers for services not defined in the
|
||||
Compose file
|
||||
```
|
||||
|
||||
Stops containers and removes containers, networks, volumes, and images
|
||||
created by `up`.
|
||||
|
||||
By default, the only things removed are:
|
||||
|
||||
- Containers for services defined in the Compose file
|
||||
- Networks defined in the `networks` section of the Compose file
|
||||
- The default network, if one is used
|
||||
|
||||
Networks and volumes defined as `external` are never removed.
|
|
@ -1,92 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "CLI Environment Variables"
|
||||
description = "CLI Environment Variables"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, reference"]
|
||||
[menu.main]
|
||||
parent = "smn_compose_cli"
|
||||
weight=-1
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# CLI Environment Variables
|
||||
|
||||
Several environment variables are available for you to configure the Docker Compose command-line behaviour.
|
||||
|
||||
Variables starting with `DOCKER_` are the same as those used to configure the
|
||||
Docker command-line client. If you're using `docker-machine`, then the `eval "$(docker-machine env my-docker-vm)"` command should set them to their correct values. (In this example, `my-docker-vm` is the name of a machine you created.)
|
||||
|
||||
> Note: Some of these variables can also be provided using an
|
||||
> [environment file](../env-file.md)
|
||||
|
||||
## COMPOSE\_PROJECT\_NAME
|
||||
|
||||
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 `myapp` and it includes two services `db` and `web` then compose starts containers named `myapp_db_1` and `myapp_web_1` respectively.
|
||||
|
||||
Setting this is optional. If you do not set this, the `COMPOSE_PROJECT_NAME`
|
||||
defaults to the `basename` of the project directory. See also the `-p`
|
||||
[command-line option](overview.md).
|
||||
|
||||
## COMPOSE\_FILE
|
||||
|
||||
Specify the path to a Compose file. If not provided, Compose looks for a file named
|
||||
`docker-compose.yml` in the current directory and then each parent directory in
|
||||
succession until a file by that name is found.
|
||||
|
||||
This variable supports multiple compose files separate by a path separator (on
|
||||
Linux and OSX the path separator is `:`, on Windows it is `;`). For example:
|
||||
`COMPOSE_FILE=docker-compose.yml:docker-compose.prod.yml`
|
||||
|
||||
See also the `-f` [command-line option](overview.md).
|
||||
|
||||
## COMPOSE\_API\_VERSION
|
||||
|
||||
The Docker API only supports requests from clients which report a specific
|
||||
version. If you receive a `client and server don't have same version error` using
|
||||
`docker-compose`, you can workaround this error by setting this environment
|
||||
variable. Set the version value to match the server version.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
## DOCKER\_HOST
|
||||
|
||||
Sets the URL of the `docker` daemon. As with the Docker client, defaults to `unix:///var/run/docker.sock`.
|
||||
|
||||
## DOCKER\_TLS\_VERIFY
|
||||
|
||||
When set to anything other than an empty string, enables TLS communication with
|
||||
the `docker` daemon.
|
||||
|
||||
## DOCKER\_CERT\_PATH
|
||||
|
||||
Configures the path to the `ca.pem`, `cert.pem`, and `key.pem` files used for TLS verification. Defaults to `~/.docker`.
|
||||
|
||||
## COMPOSE\_HTTP\_TIMEOUT
|
||||
|
||||
Configures the time (in seconds) a request to the Docker daemon is allowed to hang before Compose considers
|
||||
it failed. Defaults to 60 seconds.
|
||||
|
||||
## COMPOSE\_TLS\_VERSION
|
||||
|
||||
Configure which TLS version is used for TLS communication with the `docker`
|
||||
daemon. Defaults to `TLSv1`.
|
||||
Supported values are: `TLSv1`, `TLSv1_1`, `TLSv1_2`.
|
||||
|
||||
## Related Information
|
||||
|
||||
- [User guide](../index.md)
|
||||
- [Installing Compose](../install.md)
|
||||
- [Compose file reference](../compose-file.md)
|
||||
- [Environment file](../env-file.md)
|
|
@ -1,34 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "events"
|
||||
description = "Receive real time events from containers."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, events"]
|
||||
[menu.main]
|
||||
identifier="events.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# events
|
||||
|
||||
```
|
||||
Usage: events [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
--json Output events as a stream of json objects
|
||||
```
|
||||
|
||||
Stream container events for every container in the project.
|
||||
|
||||
With the `--json` flag, a json object will be printed one per line with the
|
||||
format:
|
||||
|
||||
```
|
||||
{
|
||||
"service": "web",
|
||||
"event": "create",
|
||||
"container": "213cf75fc39a",
|
||||
"image": "alpine:edge",
|
||||
"time": "2015-11-20T18:01:03.615550",
|
||||
}
|
||||
```
|
|
@ -1,29 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "exec"
|
||||
description = "exec"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, exec"]
|
||||
[menu.main]
|
||||
identifier="exec.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# exec
|
||||
|
||||
```
|
||||
Usage: exec [options] SERVICE COMMAND [ARGS...]
|
||||
|
||||
Options:
|
||||
-d Detached mode: Run command in the background.
|
||||
--privileged Give extended privileges to the process.
|
||||
--user USER Run the command as this user.
|
||||
-T Disable pseudo-tty allocation. By default `docker-compose exec`
|
||||
allocates a TTY.
|
||||
--index=index index of the container if there are multiple
|
||||
instances of a service [default: 1]
|
||||
```
|
||||
|
||||
This is equivalent of `docker exec`. With this subcommand you can run arbitrary
|
||||
commands in your services. Commands are by default allocating a TTY, so you can
|
||||
do e.g. `docker-compose exec web sh` to get an interactive prompt.
|
|
@ -1,18 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "help"
|
||||
description = "help"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, help"]
|
||||
[menu.main]
|
||||
identifier="help.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# help
|
||||
|
||||
```
|
||||
Usage: help COMMAND
|
||||
```
|
||||
|
||||
Displays help and usage instructions for a command.
|
|
@ -1,42 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Command-line Reference"
|
||||
description = "Compose CLI reference"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, reference"]
|
||||
[menu.main]
|
||||
identifier = "smn_compose_cli"
|
||||
parent = "workw_compose"
|
||||
weight=80
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
## Compose command-line reference
|
||||
|
||||
The following pages describe the usage information for the [docker-compose](overview.md) subcommands. You can also see this information by running `docker-compose [SUBCOMMAND] --help` from the command line.
|
||||
|
||||
* [docker-compose](overview.md)
|
||||
* [build](build.md)
|
||||
* [config](config.md)
|
||||
* [create](create.md)
|
||||
* [down](down.md)
|
||||
* [events](events.md)
|
||||
* [help](help.md)
|
||||
* [kill](kill.md)
|
||||
* [logs](logs.md)
|
||||
* [pause](pause.md)
|
||||
* [port](port.md)
|
||||
* [ps](ps.md)
|
||||
* [pull](pull.md)
|
||||
* [restart](restart.md)
|
||||
* [rm](rm.md)
|
||||
* [run](run.md)
|
||||
* [scale](scale.md)
|
||||
* [start](start.md)
|
||||
* [stop](stop.md)
|
||||
* [unpause](unpause.md)
|
||||
* [up](up.md)
|
||||
|
||||
## Where to go next
|
||||
|
||||
* [CLI environment variables](envvars.md)
|
||||
* [docker-compose Command](overview.md)
|
|
@ -1,24 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "kill"
|
||||
description = "Forces running containers to stop."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, kill"]
|
||||
[menu.main]
|
||||
identifier="kill.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# kill
|
||||
|
||||
```
|
||||
Usage: kill [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
-s SIGNAL SIGNAL to send to the container. Default signal is SIGKILL.
|
||||
```
|
||||
|
||||
Forces running containers to stop by sending a `SIGKILL` signal. Optionally the
|
||||
signal can be passed, for example:
|
||||
|
||||
$ docker-compose kill -s SIGINT
|
|
@ -1,25 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "logs"
|
||||
description = "Displays log output from services."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, logs"]
|
||||
[menu.main]
|
||||
identifier="logs.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# logs
|
||||
|
||||
```
|
||||
Usage: logs [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
--no-color Produce monochrome output.
|
||||
-f, --follow Follow log output
|
||||
-t, --timestamps Show timestamps
|
||||
--tail Number of lines to show from the end of the logs
|
||||
for each container.
|
||||
```
|
||||
|
||||
Displays log output from services.
|
|
@ -1,127 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Overview of docker-compose CLI"
|
||||
description = "Overview of docker-compose CLI"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, docker-compose"]
|
||||
aliases = ["/compose/reference/docker-compose/"]
|
||||
[menu.main]
|
||||
parent = "smn_compose_cli"
|
||||
weight=-2
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Overview of docker-compose CLI
|
||||
|
||||
This page provides the usage information for the `docker-compose` Command.
|
||||
You can also see this information by running `docker-compose --help` from the
|
||||
command line.
|
||||
|
||||
```
|
||||
Define and run multi-container applications with Docker.
|
||||
|
||||
Usage:
|
||||
docker-compose [-f=<arg>...] [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
|
||||
|
||||
```
|
||||
|
||||
The Docker Compose binary. You use this command to build and manage multiple
|
||||
services in Docker containers.
|
||||
|
||||
Use the `-f` flag to specify the location of a Compose configuration file. You
|
||||
can supply multiple `-f` 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.
|
||||
|
||||
For example, consider this command line:
|
||||
|
||||
```
|
||||
$ docker-compose -f docker-compose.yml -f docker-compose.admin.yml run backup_db`
|
||||
```
|
||||
|
||||
The `docker-compose.yml` file might specify a `webapp` service.
|
||||
|
||||
```
|
||||
webapp:
|
||||
image: examples/web
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- "/data"
|
||||
```
|
||||
|
||||
If the `docker-compose.admin.yml` also specifies this same service, any matching
|
||||
fields will override the previous file. New values, add to the `webapp` service
|
||||
configuration.
|
||||
|
||||
```
|
||||
webapp:
|
||||
build: .
|
||||
environment:
|
||||
- DEBUG=1
|
||||
```
|
||||
|
||||
Use a `-f` with `-` (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.
|
||||
|
||||
The `-f` flag is optional. If you don't provide this flag on the command line,
|
||||
Compose traverses the working directory and its parent directories looking for a
|
||||
`docker-compose.yml` and a `docker-compose.override.yml` file. You must
|
||||
supply at least the `docker-compose.yml` file. If both files are present on the
|
||||
same directory level, Compose combines the two files into a single configuration.
|
||||
The configuration in the `docker-compose.override.yml` file is applied over and
|
||||
in addition to the values in the `docker-compose.yml` file.
|
||||
|
||||
See also the `COMPOSE_FILE` [environment variable](envvars.md#compose-file).
|
||||
|
||||
Each configuration has a project name. If you supply a `-p` flag, you can
|
||||
specify a project name. If you don't specify the flag, Compose uses the current
|
||||
directory name. See also the `COMPOSE_PROJECT_NAME` [environment variable](
|
||||
envvars.md#compose-project-name)
|
||||
|
||||
|
||||
## Where to go next
|
||||
|
||||
* [CLI environment variables](envvars.md)
|
|
@ -1,18 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "pause"
|
||||
description = "Pauses running containers for a service."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, pause"]
|
||||
[menu.main]
|
||||
identifier="pause.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# pause
|
||||
|
||||
```
|
||||
Usage: pause [SERVICE...]
|
||||
```
|
||||
|
||||
Pauses running containers of a service. They can be unpaused with `docker-compose unpause`.
|
|
@ -1,23 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "port"
|
||||
description = "Prints the public port for a port binding.s"
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, port"]
|
||||
[menu.main]
|
||||
identifier="port.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# port
|
||||
|
||||
```
|
||||
Usage: port [options] SERVICE PRIVATE_PORT
|
||||
|
||||
Options:
|
||||
--protocol=proto tcp or udp [default: tcp]
|
||||
--index=index index of the container if there are multiple
|
||||
instances of a service [default: 1]
|
||||
```
|
||||
|
||||
Prints the public port for a port binding.
|
|
@ -1,21 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "ps"
|
||||
description = "Lists containers."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, ps"]
|
||||
[menu.main]
|
||||
identifier="ps.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# ps
|
||||
|
||||
```
|
||||
Usage: ps [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
-q Only display IDs
|
||||
```
|
||||
|
||||
Lists containers.
|
|
@ -1,21 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "pull"
|
||||
description = "Pulls service images."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, pull"]
|
||||
[menu.main]
|
||||
identifier="pull.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# pull
|
||||
|
||||
```
|
||||
Usage: pull [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
--ignore-pull-failures Pull what it can and ignores images with pull failures.
|
||||
```
|
||||
|
||||
Pulls service images.
|
|
@ -1,21 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "push"
|
||||
description = "Pushes service images."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, push"]
|
||||
[menu.main]
|
||||
identifier="push.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# push
|
||||
|
||||
```
|
||||
Usage: push [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
--ignore-push-failures Push what it can and ignores images with push failures.
|
||||
```
|
||||
|
||||
Pushes images for services.
|
|
@ -1,21 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "restart"
|
||||
description = "Restarts Docker Compose services."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, restart"]
|
||||
[menu.main]
|
||||
identifier="restart.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# restart
|
||||
|
||||
```
|
||||
Usage: restart [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds. (default: 10)
|
||||
```
|
||||
|
||||
Restarts services.
|
|
@ -1,28 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "rm"
|
||||
description = "Removes stopped service containers."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, rm"]
|
||||
[menu.main]
|
||||
identifier="rm.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# rm
|
||||
|
||||
```
|
||||
Usage: rm [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
-f, --force Don't ask to confirm removal
|
||||
-v Remove any anonymous volumes attached to containers
|
||||
-a, --all Deprecated - no effect.
|
||||
```
|
||||
|
||||
Removes stopped service containers.
|
||||
|
||||
By default, anonymous volumes attached to containers will not be removed. You
|
||||
can override this with `-v`. To list all volumes, use `docker volume ls`.
|
||||
|
||||
Any data which is not in a volume will be lost.
|
|
@ -1,56 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "run"
|
||||
description = "Runs a one-off command on a service."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, run"]
|
||||
[menu.main]
|
||||
identifier="run.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# run
|
||||
|
||||
```
|
||||
Usage: run [options] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]
|
||||
|
||||
Options:
|
||||
-d Detached mode: Run container in the background, print
|
||||
new container name.
|
||||
--name NAME Assign a name to the container
|
||||
--entrypoint CMD Override the entrypoint of the image.
|
||||
-e KEY=VAL Set an environment variable (can be used multiple times)
|
||||
-u, --user="" Run as specified username or uid
|
||||
--no-deps Don't start linked services.
|
||||
--rm Remove container after run. Ignored in detached mode.
|
||||
-p, --publish=[] Publish a container's port(s) to the host
|
||||
--service-ports Run command with the service's ports enabled and mapped to the host.
|
||||
-T Disable pseudo-tty allocation. By default `docker-compose run` allocates a TTY.
|
||||
-w, --workdir="" Working directory inside the container
|
||||
```
|
||||
|
||||
Runs a one-time command against a service. For example, the following command starts the `web` service and runs `bash` as its command.
|
||||
|
||||
$ docker-compose run web bash
|
||||
|
||||
Commands you use with `run` start in new containers with the same configuration as defined by the service' configuration. This means the container has the same volumes, links, as defined in the configuration file. There two differences though.
|
||||
|
||||
First, the command passed by `run` overrides the command defined in the service configuration. For example, if the `web` service configuration is started with `bash`, then `docker-compose run web python app.py` overrides it with `python app.py`.
|
||||
|
||||
The second difference is the `docker-compose run` command does not create any of the ports specified in the service configuration. This prevents the port collisions with already open ports. If you *do want* the service's ports created and mapped to the host, specify the `--service-ports` flag:
|
||||
|
||||
$ docker-compose run --service-ports web python manage.py shell
|
||||
|
||||
Alternatively manual port mapping can be specified. Same as when running Docker's `run` command - using `--publish` or `-p` options:
|
||||
|
||||
$ docker-compose run --publish 8080:80 -p 2022:22 -p 127.0.0.1:2021:21 web python manage.py shell
|
||||
|
||||
If you start a service configured with links, the `run` command first checks to see if the linked service is running and starts the service if it is stopped. Once all the linked services are running, the `run` executes the command you passed it. So, for example, you could run:
|
||||
|
||||
$ docker-compose run db psql -h db -U docker
|
||||
|
||||
This would open up an interactive PostgreSQL shell for the linked `db` container.
|
||||
|
||||
If you do not want the `run` command to start linked containers, specify the `--no-deps` flag:
|
||||
|
||||
$ docker-compose run --no-deps web python manage.py shell
|
|
@ -1,21 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "scale"
|
||||
description = "Sets the number of containers to run for a service."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, scale"]
|
||||
[menu.main]
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# scale
|
||||
|
||||
```
|
||||
Usage: scale [SERVICE=NUM...]
|
||||
```
|
||||
|
||||
Sets the number of containers to run for a service.
|
||||
|
||||
Numbers are specified as arguments in the form `service=num`. For example:
|
||||
|
||||
$ docker-compose scale web=2 worker=3
|
|
@ -1,18 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "start"
|
||||
description = "Starts existing containers for a service."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, start"]
|
||||
[menu.main]
|
||||
identifier="start.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# start
|
||||
|
||||
```
|
||||
Usage: start [SERVICE...]
|
||||
```
|
||||
|
||||
Starts existing containers for a service.
|
|
@ -1,22 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "stop"
|
||||
description = "Stops running containers without removing them. "
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, stop"]
|
||||
[menu.main]
|
||||
identifier="stop.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# stop
|
||||
|
||||
```
|
||||
Usage: stop [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds (default: 10).
|
||||
```
|
||||
|
||||
Stops running containers without removing them. They can be started again with
|
||||
`docker-compose start`.
|
|
@ -1,18 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "unpause"
|
||||
description = "Unpauses paused containers for a service."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, unpause"]
|
||||
[menu.main]
|
||||
identifier="unpause.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# unpause
|
||||
|
||||
```
|
||||
Usage: unpause [SERVICE...]
|
||||
```
|
||||
|
||||
Unpauses paused containers of a service.
|
|
@ -1,55 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "up"
|
||||
description = "Builds, (re)creates, starts, and attaches to containers for a service."
|
||||
keywords = ["fig, composition, compose, docker, orchestration, cli, up"]
|
||||
[menu.main]
|
||||
identifier="up.compose"
|
||||
parent = "smn_compose_cli"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# up
|
||||
|
||||
```
|
||||
Usage: up [options] [SERVICE...]
|
||||
|
||||
Options:
|
||||
-d Detached mode: Run containers in the background,
|
||||
print new container names.
|
||||
Incompatible with --abort-on-container-exit.
|
||||
--no-color Produce monochrome output.
|
||||
--no-deps Don't start linked services.
|
||||
--force-recreate Recreate containers even if their configuration
|
||||
and image haven't changed.
|
||||
Incompatible with --no-recreate.
|
||||
--no-recreate If containers already exist, don't recreate them.
|
||||
Incompatible with --force-recreate.
|
||||
--no-build Don't build an image, even if it's missing.
|
||||
--build Build images before starting containers.
|
||||
--abort-on-container-exit Stops all containers if any container was stopped.
|
||||
Incompatible with -d.
|
||||
-t, --timeout TIMEOUT Use this timeout in seconds for container shutdown
|
||||
when attached or when containers are already
|
||||
running. (default: 10)
|
||||
--remove-orphans Remove containers for services not defined in
|
||||
the Compose file
|
||||
|
||||
```
|
||||
|
||||
Builds, (re)creates, starts, and attaches to containers for a service.
|
||||
|
||||
Unless they are already running, this command also starts any linked services.
|
||||
|
||||
The `docker-compose up` command aggregates the output of each container. When
|
||||
the command exits, all containers are stopped. Running `docker-compose up -d`
|
||||
starts the containers in the background and leaves them running.
|
||||
|
||||
If there are existing containers for a service, and the service's configuration
|
||||
or image was changed after the container's creation, `docker-compose up` picks
|
||||
up the changes by stopping and recreating the containers (preserving mounted
|
||||
volumes). To prevent Compose from picking up changes, use the `--no-recreate`
|
||||
flag.
|
||||
|
||||
If you want to force Compose to stop and recreate all containers, use the
|
||||
`--force-recreate` flag.
|
|
@ -1,88 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Controlling startup order"
|
||||
description = "How to control service startup order in Docker Compose"
|
||||
keywords = "documentation, docs, docker, compose, startup, order"
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=90
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
# Controlling startup order in Compose
|
||||
|
||||
You can control the order of service startup with the
|
||||
[depends_on](compose-file.md#depends-on) option. Compose always starts
|
||||
containers in dependency order, where dependencies are determined by
|
||||
`depends_on`, `links`, `volumes_from` and `network_mode: "service:..."`.
|
||||
|
||||
However, Compose will not wait until a container is "ready" (whatever that means
|
||||
for your particular application) - only until it's running. There's a good
|
||||
reason for this.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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't
|
||||
need this level of resilience, you can work around the problem with a wrapper
|
||||
script:
|
||||
|
||||
- Use a tool such as [wait-for-it](https://github.com/vishnubob/wait-for-it)
|
||||
or [dockerize](https://github.com/jwilder/dockerize). These are small
|
||||
wrapper scripts which you can include in your application's image and will
|
||||
poll a given host and port until it's accepting TCP connections.
|
||||
|
||||
Supposing your application's image has a `CMD` set in its Dockerfile, you
|
||||
can wrap it by setting the entrypoint in `docker-compose.yml`:
|
||||
|
||||
version: "2"
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "80:8000"
|
||||
depends_on:
|
||||
- "db"
|
||||
entrypoint: ./wait-for-it.sh db:5432
|
||||
db:
|
||||
image: postgres
|
||||
|
||||
- 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:
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
host="$1"
|
||||
shift
|
||||
cmd="$@"
|
||||
|
||||
until psql -h "$host" -U "postgres" -c '\l'; do
|
||||
>&2 echo "Postgres is unavailable - sleeping"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
>&2 echo "Postgres is up - executing command"
|
||||
exec $cmd
|
||||
|
||||
You can use this as a wrapper script as in the previous example, by setting
|
||||
`entrypoint: ./wait-for-postgres.sh db`.
|
||||
|
||||
|
||||
## Compose documentation
|
||||
|
||||
- [Installing Compose](install.md)
|
||||
- [Get started with Django](django.md)
|
||||
- [Get started with Rails](rails.md)
|
||||
- [Get started with WordPress](wordpress.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
185
docs/swarm.md
185
docs/swarm.md
|
@ -1,185 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Using Compose with Swarm"
|
||||
description = "How to use Compose and Swarm together to deploy apps to multi-host clusters"
|
||||
keywords = ["documentation, docs, docker, compose, orchestration, containers, swarm"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Using Compose with Swarm
|
||||
|
||||
> **Note:** “Swarm” here refers to [Docker Swarm](/swarm/overview.md), a product separate from Docker Engine. It does _not_ refer to [swarm mode](/engine/swarm), which is a built-in feature of Docker Engine introduced in version 1.12.
|
||||
>
|
||||
> Integration between Compose and swarm mode is at the experimental stage. See [Docker Stacks and Bundles](bundles.md) for details.
|
||||
|
||||
Docker Compose and [Docker Swarm](/swarm/overview.md) aim to have full integration, meaning
|
||||
you can point a Compose app at a Swarm cluster and have it all just work as if
|
||||
you were using a single Docker host.
|
||||
|
||||
The actual extent of integration depends on which version of the [Compose file
|
||||
format](compose-file.md#versioning) you are using:
|
||||
|
||||
1. If you're using version 1 along with `links`, your app will work, but Swarm
|
||||
will schedule all containers on one host, because links between containers
|
||||
do not work across hosts with the old networking system.
|
||||
|
||||
2. If you're using version 2, your app should work with no changes:
|
||||
|
||||
- subject to the [limitations](#limitations) described below,
|
||||
|
||||
- as long as the Swarm cluster is configured to use the [overlay driver](https://docs.docker.com/engine/userguide/networking/dockernetworks/#an-overlay-network),
|
||||
or a custom driver which supports multi-host networking.
|
||||
|
||||
Read [Get started with multi-host networking](https://docs.docker.com/engine/userguide/networking/get-started-overlay/) to see how to
|
||||
set up a Swarm cluster with [Docker Machine](/machine/overview.md) and the overlay driver. Once you've got it running, deploying your app to it should be as simple as:
|
||||
|
||||
$ eval "$(docker-machine env --swarm <name of swarm master machine>)"
|
||||
$ docker-compose up
|
||||
|
||||
|
||||
## Limitations
|
||||
|
||||
### Building images
|
||||
|
||||
Swarm can build an image from a Dockerfile just like a single-host Docker
|
||||
instance can, but the resulting image will only live on a single node and won't
|
||||
be distributed to other nodes.
|
||||
|
||||
If you want to use Compose to scale the service in question to multiple nodes,
|
||||
you'll have to build it yourself, push it to a registry (e.g. the Docker Hub)
|
||||
and reference it from `docker-compose.yml`:
|
||||
|
||||
$ docker build -t myusername/web .
|
||||
$ docker push myusername/web
|
||||
|
||||
$ cat docker-compose.yml
|
||||
web:
|
||||
image: myusername/web
|
||||
|
||||
$ docker-compose up -d
|
||||
$ docker-compose scale web=3
|
||||
|
||||
### Multiple dependencies
|
||||
|
||||
If a service has multiple dependencies of the type which force co-scheduling
|
||||
(see [Automatic scheduling](#automatic-scheduling) below), it's possible that
|
||||
Swarm will schedule the dependencies on different nodes, making the dependent
|
||||
service impossible to schedule. For example, here `foo` needs to be co-scheduled
|
||||
with `bar` and `baz`:
|
||||
|
||||
version: "2"
|
||||
services:
|
||||
foo:
|
||||
image: foo
|
||||
volumes_from: ["bar"]
|
||||
network_mode: "service:baz"
|
||||
bar:
|
||||
image: bar
|
||||
baz:
|
||||
image: baz
|
||||
|
||||
The problem is that Swarm might first schedule `bar` and `baz` on different
|
||||
nodes (since they're not dependent on one another), making it impossible to
|
||||
pick an appropriate node for `foo`.
|
||||
|
||||
To work around this, use [manual scheduling](#manual-scheduling) to ensure that
|
||||
all three services end up on the same node:
|
||||
|
||||
version: "2"
|
||||
services:
|
||||
foo:
|
||||
image: foo
|
||||
volumes_from: ["bar"]
|
||||
network_mode: "service:baz"
|
||||
environment:
|
||||
- "constraint:node==node-1"
|
||||
bar:
|
||||
image: bar
|
||||
environment:
|
||||
- "constraint:node==node-1"
|
||||
baz:
|
||||
image: baz
|
||||
environment:
|
||||
- "constraint:node==node-1"
|
||||
|
||||
### Host ports and recreating containers
|
||||
|
||||
If a service maps a port from the host, e.g. `80:8000`, then you may get an
|
||||
error like this when running `docker-compose up` on it after the first time:
|
||||
|
||||
docker: Error response from daemon: unable to find a node that satisfies
|
||||
container==6ab2dfe36615ae786ef3fc35d641a260e3ea9663d6e69c5b70ce0ca6cb373c02.
|
||||
|
||||
The usual cause of this error is that the container has a volume (defined either
|
||||
in its image or in the Compose file) without an explicit mapping, and so in
|
||||
order to preserve its data, Compose has directed Swarm to schedule the new
|
||||
container on the same node as the old container. This results in a port clash.
|
||||
|
||||
There are two viable workarounds for this problem:
|
||||
|
||||
- Specify a named volume, and use a volume driver which is capable of mounting
|
||||
the volume into the container regardless of what node it's scheduled on.
|
||||
|
||||
Compose does not give Swarm any specific scheduling instructions if a
|
||||
service uses only named volumes.
|
||||
|
||||
version: "2"
|
||||
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "80:8000"
|
||||
volumes:
|
||||
- web-logs:/var/log/web
|
||||
|
||||
volumes:
|
||||
web-logs:
|
||||
driver: custom-volume-driver
|
||||
|
||||
- Remove the old container before creating the new one. You will lose any data
|
||||
in the volume.
|
||||
|
||||
$ docker-compose stop web
|
||||
$ docker-compose rm -f web
|
||||
$ docker-compose up web
|
||||
|
||||
|
||||
## Scheduling containers
|
||||
|
||||
### Automatic scheduling
|
||||
|
||||
Some configuration options will result in containers being automatically
|
||||
scheduled on the same Swarm node to ensure that they work correctly. These are:
|
||||
|
||||
- `network_mode: "service:..."` and `network_mode: "container:..."` (and
|
||||
`net: "container:..."` in the version 1 file format).
|
||||
|
||||
- `volumes_from`
|
||||
|
||||
- `links`
|
||||
|
||||
### Manual scheduling
|
||||
|
||||
Swarm offers a rich set of scheduling and affinity hints, enabling you to
|
||||
control where containers are located. They are specified via container
|
||||
environment variables, so you can use Compose's `environment` option to set
|
||||
them.
|
||||
|
||||
# Schedule containers on a specific node
|
||||
environment:
|
||||
- "constraint:node==node-1"
|
||||
|
||||
# Schedule containers on a node that has the 'storage' label set to 'ssd'
|
||||
environment:
|
||||
- "constraint:storage==ssd"
|
||||
|
||||
# Schedule containers where the 'redis' image is already pulled
|
||||
environment:
|
||||
- "affinity:image==redis"
|
||||
|
||||
For the full set of available filters and expressions, see the [Swarm
|
||||
documentation](/swarm/scheduler/filter.md).
|
|
@ -1,112 +0,0 @@
|
|||
<!--[metadata]>
|
||||
+++
|
||||
title = "Quickstart: Compose and WordPress"
|
||||
description = "Getting started with Compose and WordPress"
|
||||
keywords = ["documentation, docs, docker, compose, orchestration, containers"]
|
||||
[menu.main]
|
||||
parent="workw_compose"
|
||||
weight=6
|
||||
+++
|
||||
<![end-metadata]-->
|
||||
|
||||
|
||||
# Quickstart: Docker Compose and WordPress
|
||||
|
||||
You can use Docker Compose to easily run WordPress in an isolated environment built
|
||||
with Docker containers. This quick-start guide demonstrates how to use Compose to set up and run WordPress. Before starting, you'll need to have
|
||||
[Compose installed](install.md).
|
||||
|
||||
### Define the project
|
||||
|
||||
1. Create an empty project directory.
|
||||
|
||||
You can name the directory something easy for you to remember. This directory is the context for your application image. The directory should only contain resources to build that image.
|
||||
|
||||
This project directory will contain a `docker-compose.yaml` file which will be complete in itself for a good starter wordpress project.
|
||||
|
||||
2. Change directories into your project directory.
|
||||
|
||||
For example, if you named your directory `my_wordpress`:
|
||||
|
||||
$ cd my-wordpress/
|
||||
|
||||
3. Create a `docker-compose.yml` file that will start your `Wordpress` blog and a separate `MySQL` instance with a volume mount for data persistence:
|
||||
|
||||
version: '2'
|
||||
services:
|
||||
db:
|
||||
image: mysql:5.7
|
||||
volumes:
|
||||
- "./.data/db:/var/lib/mysql"
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: wordpress
|
||||
MYSQL_DATABASE: wordpress
|
||||
MYSQL_USER: wordpress
|
||||
MYSQL_PASSWORD: wordpress
|
||||
|
||||
wordpress:
|
||||
depends_on:
|
||||
- db
|
||||
image: wordpress:latest
|
||||
links:
|
||||
- db
|
||||
ports:
|
||||
- "8000:80"
|
||||
restart: always
|
||||
environment:
|
||||
WORDPRESS_DB_HOST: db:3306
|
||||
WORDPRESS_DB_PASSWORD: wordpress
|
||||
|
||||
**NOTE**: The folder `./.data/db` will be automatically created in the project directory
|
||||
alongside the `docker-compose.yml` which will persist any updates made by wordpress to the
|
||||
database.
|
||||
|
||||
### Build the project
|
||||
|
||||
Now, run `docker-compose up -d` from your project directory.
|
||||
|
||||
This pulls the needed images, and starts the wordpress and database containers, as shown in the example below.
|
||||
|
||||
$ docker-compose up -d
|
||||
Creating network "my_wordpress_default" with the default driver
|
||||
Pulling db (mysql:5.7)...
|
||||
5.7: Pulling from library/mysql
|
||||
efd26ecc9548: Pull complete
|
||||
a3ed95caeb02: Pull complete
|
||||
...
|
||||
Digest: sha256:34a0aca88e85f2efa5edff1cea77cf5d3147ad93545dbec99cfe705b03c520de
|
||||
Status: Downloaded newer image for mysql:5.7
|
||||
Pulling wordpress (wordpress:latest)...
|
||||
latest: Pulling from library/wordpress
|
||||
efd26ecc9548: Already exists
|
||||
a3ed95caeb02: Pull complete
|
||||
589a9d9a7c64: Pull complete
|
||||
...
|
||||
Digest: sha256:ed28506ae44d5def89075fd5c01456610cd6c64006addfe5210b8c675881aff6
|
||||
Status: Downloaded newer image for wordpress:latest
|
||||
Creating my_wordpress_db_1
|
||||
Creating my_wordpress_wordpress_1
|
||||
|
||||
### Bring up WordPress in a web browser
|
||||
|
||||
If you're using [Docker Machine](https://docs.docker.com/machine/), then `docker-machine ip MACHINE_VM` gives you the machine address and you can open `http://MACHINE_VM_IP:8000` in a browser.
|
||||
|
||||
At this point, WordPress should be running on port `8000` of your Docker Host, and you can complete the "famous five-minute installation" as a WordPress administrator.
|
||||
|
||||
**NOTE**: The Wordpress site will not be immediately available on port `8000` because the containers are still being initialized and may take a couple of minutes before the first load.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
|
||||
## More Compose documentation
|
||||
|
||||
- [User guide](index.md)
|
||||
- [Installing Compose](install.md)
|
||||
- [Getting Started](gettingstarted.md)
|
||||
- [Get started with Django](django.md)
|
||||
- [Get started with Rails](rails.md)
|
||||
- [Command line reference](./reference/index.md)
|
||||
- [Compose file reference](compose-file.md)
|
Loading…
Reference in New Issue