【Docker 系列】docker 学习九,Compose 内容编排官网初步体验

我们前面的文章学习了 docker ,为什么还要 Compose 呢?Compose到底是个啥玩意?

Docker Compose 可以来轻松的高效的管理容器,定义运行多个容器

咱们一起来看看官方的介绍 docs

Compose 是什么

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.

讲了三个点:

  • Compose 可以定义和运行多个容器
  • 需要使用给到 YAML 配置文件
  • 单个命令就可以创建和启动所有的服务

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.

Docker Compose 可以运行在所有的环境中

Using Compose is basically a three-step process:

1、Define your app’s environment with a Dockerfileso it can be reproduced anywhere.

2、Define the services that make up your app in docker-compose.ymlso they can be run together in an isolated environment.

3、Run docker compose up and the Docker compose command starts and runs your entire app. You can alternatively run docker-compose up using the docker-compose binary.

三个步骤:

  • 需要定义好 Dockerfile ,保证它在任何环境都能运行
  • 在 docker-compose.yml 文件中定义好 services,那么这个 yml 文件如何写呢?services 咋定义呢
  • 使用docker-compose binary启动项目

总结上述官方说明:

Docker Compose 用于批量容器编排

如果一个项目中的多个微服务(几十个或者几百个),我们都一个一个的使用docker run是不是很傻?而且对于运维来说也是一个非常不友好的事情,优化这样的问题,我们有了 Docker Compose

Compose 在 Docker 中默认就有吗?

Docker 中默认是没有 Compose 的,Compose 是 Docker 官方的开源项目,我们使用 Compose ,是需要自己另外安装的

Compose 的 yml 文件如何编写?

一起来看看官方文档的 yml 是怎样的结构:

A docker-compose.yml looks like this:

version: "3.9"  # optional since v1.27.0
services:
  web:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - .:/code
      - logvolume01:/var/log
    links:
      - redis
  redis:
    image: redis
volumes:
  logvolume01: {
   
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值