Overview of Docker Compose(源码翻译)

Overview of Docker Compose

Docker Compose 概览,预计阅读时间 5分钟

 

Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with 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.

 

Docker Compose 是用于定义和运行多容器Docker应用程序的工具。使用组合,可以使用YAML文件配置应用程序的服务。然后,使用一个命令从配置中创建并启动所有服务。要更多地了解Compose的所有特性,请参见特性列表。

 

注: 所有属性连接:https://docs.docker.com/compose/overview/#features

 

Compose works in all environments: production, staging, development, testing, as well as CI workflows. You can learn more about each case in Common Use Cases.

 

Compose 可以运行一下生产环境:生产、阶段、开发、测试以及CI工作流。您可以了解关于常见用例中的每个用例的更多信息。

 

注:用例地址:https://docs.docker.com/compose/overview/#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.
  1. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
  1. Run docker-compose up and Compose starts and runs your entire app.

使用组合基本上是一个三步的过程:

  1. 使用Dockerfile定义应用程序的环境,以便可以在任何地方复制它。
  1. 在docker-compose中定义组成应用程序的服务。因此,它们可以在一个隔离的环境中一起运行。
  1. 运行docker-撰写和撰写启动和运行您的整个应用程序。

 

一个dockerfile 可能长成这个样子:

version: '3'

services:

web:

build: .

ports:

- "5000:5000"

volumes:

- .:/code

- logvolume01:/var/log

links:

- redis

redis:

image: redis

volumes:

logvolume01: {}

 

更多关于dockerfile 配置的参考信息前往:https://docs.docker.com/compose/compose-file/

 

Compose has commands for managing the whole lifecycle of your application:

compose 管理你的应用程序的整个生命周期的命令:

 

 

  • 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

在服务上运行一次性命令

 

属性:

 

  1. Multiple isolated environments on a single host

单个主机上的多个隔离环境

  1. Compose uses a project name to isolate environments from each other. You can make use of this project name in several different contexts:

组合使用项目名称将环境彼此隔离。您可以在几个不同的上下文中使用这个项目名称:

疑问:这个Context具体改如何理解?

 

on a dev host, to create multiple copies of a single environment, such as when 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

在CI服务器上,为了防止构建相互干扰,可以将项目名称设置为惟一的构建号

 

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 or the COMPOSE_PROJECT_NAME environment variable.

 

默认的项目名称是项目目录的basename。可以使用-p命令行选项或COMPOSE_PROJECT_NAME环境变量设置自定义项目名称。

 

  1. 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.

 

compose保存服务使用的所有卷。当docker- up运行时,如果它从以前的运行中找到任何容器,它就会将卷从旧容器复制到新容器。这个过程确保您在卷中创建的任何数据不会丢失。

 

If you use docker-compose on a Windows machine, see Environment variables and adjust the necessary environment variables for your specific needs.

 

如果在Windows机器上使用docker- composition,请参阅环境变量,并根据具体需要调整必要的环境变量。

 

  1. 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.

Compose 缓存用于创建容器的配置。重新启动未更改的服务时,组合将重用现有容器。重用容器意味着您可以非常快速地对环境进行更改。

 

  1. 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 for more details.

 

Compose 支持组合文件中的变量。您可以使用这些变量为不同的环境或不同的用户定制组合。有关更多细节,请参见变量替换。

 

注:文中连接:https://docs.docker.com/compose/compose-file/#variable-substitution

 

You can extend a Compose file using the extends field or by creating multiple Compose files. See extends for more details.

 

您可以使用extends字段或通过创建多个组合文件来扩展组合文件。有关更多细节,请参见extends。

 

以下略过 Common use case

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值