Overview of Docker Compose
2015-12-29 16:29
876 查看
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 servicesfrom your configuration. To learnmore about all the features of Composesee
the list of features.
Compose is great for development, testing, and staging environments, as well asCI workflows. You can learn more about each case inCommon Use Cases.
Using Compose is basically a three-step process.
Define your app’s environment with a
Dockerfileso it can bereproduced anywhere.
Define the services that make up your app in
docker-compose.ymlsothey can be run together in an isolated environment.
Lastly, run
docker-compose upand Compose will start and run your entire app.
A
docker-compose.ymllooks like this:
web: build: . ports: - "5000:5000" volumes: - .:/code links: - redis redis: image: redis
For more information about the Compose file, see theCompose file reference
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 ComposeGetting Started
Get started with Django
Get started with Rails
Get started with WordPress
Frequently asked questions
Command line reference
Compose file reference
Features
The features of Compose that make it effective are:Multiple isolated environments on a single host
Preserve volume data when containers are created
Only recreate containers that have changed
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 usethis project name to:on a dev host, to create multiple copies of a single environment (ex: you wantto 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 setthe project name to a unique build number
on a shared host or dev host, to prevent different projects which may use thesame service names, from interfering with each other
The default project name is the basename of the project directory. You can seta custom project name by using the
-pcommand line option or the
COMPOSE_PROJECT_NAME
environment variable.
Preserve volume data when containers are created
Compose preserves all volumes used by your services. Whendocker-compose upruns, if it finds any containers from previous runs, it copies the volumes fromthe old container to the new container. This process ensures that any datayou’ve created
in volumes isn’t lost.
Only recreate containers that have changed
Compose caches the configuration used to create a container. When yourestart a service that has not changed, Compose re-uses the existingcontainers. Re-using containers means that you can make changes to yourenvironment very quickly.Variables and moving a composition between environments
Compose supports variables in the Compose file. You can use these variablesto customize your composition for different environments, or different users.SeeVariable substitution for moredetails.
You can extend a Compose file using the
extendsfield or by creating multipleCompose files. See
extends for more details.
Common Use Cases
Compose can be used in many different ways. Some common use cases are outlinedbelow.Development environments
When you’re developing software, the ability to run an application in anisolated environment and interact with it is crucial. The Compose commandline tool can be used to create the environment and interact with it.The Compose file provides a way to document and configureall of the application’s service dependencies (databases, queues, caches,web service APIs, etc). Using the Compose command
line tool you can createand 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 getstarted on a project. Compose can reduce a multi-page “developer gettingstarted 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 processis the automated test suite. Automated end-to-end testing requires anenvironment in which to run tests. Compose provides a convenient way to createand destroy isolated testingenvironments for your test suite. By defining the fullenvironment in a
Compose file you can create and destroy theseenvironments in just a few commands:
$ docker-compose up -d $ ./run_tests $ docker-compose stop $ docker-compose rm -f
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 maybe a single instanceprovisioned withDocker Machine or an entireDocker Swarm cluster.
For details on using production-oriented features, seecompose in production in this documentation.
Release Notes
To see a detailed list of changes for past and current releases of DockerCompose, please refer to theCHANGELOG.Getting help
Docker Compose is under active development. If you need help, would like tocontribute, or simply want to talk about the project with like-mindedindividuals, we have a number of open channels for communication.To report bugs or file feature requests: please use the
issue tracker on Github.
To talk about the project with people in real time: please join the
#docker-composechannel on freenode IRC.
To contribute code or documentation changes: please submit a
pull request on Github.
For more information and resources, please visit the
Getting Help project page.
相关文章推荐
- Docker Swarm Overview
- Jenkins and Docker Next Generation Continuous Delivery
- 执行docker daemon命令时出错的解决方案
- 基于Mesos和Docker的分布式计算平台
- crawler_Docker_解决用 JavaScript 框架开发的 Web 站点抓取
- About Docker
- About the Docker Hub
- 读深入分析DOcker镜像原理笔记
- [Docker] - 发布镜像到你自己的库
- docker for Mac OS
- 使用shell批量删除docker容器
- 使用灵雀云免费docker修建梯子
- centos6.5 安装docker经历
- 两种方式创建你自己的 Docker 基本映像
- [置顶] Docker笔记
- What Docker?简介
- Dockerfile制作Docker镜像
- Docker命令详解
- Docker学习笔记(一)
- Docker认识理解之路