Docker进阶

一、Overview of Docker 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 works in all environments: production, staging, development, testing, as well as CI workflows. You can learn more about each case in 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. Run docker-compose up and Compose starts and runs your entire app.

即:
Using Compose is basically a three-step process:

  1. Dockerfile保证我们的项目在任何地方运行
  2. services 什么是服务
  3. docker-compose.yml文件怎么编写
  4. docker-compose up 启动项目

作用:批量容器编排
Compose是Docker官方的开源项目
,需要安装

Dockerfile让程序在任何地方运行,web服务,redis,mysql,nginx…多个容器

Compose:
A docker-compose.yml looks like this:

version: '2.0'
services:
  web:
    build: .
    ports:
    - "5000:5000"
    volumes:
    - .:/code
    - logvolume01:/var/log
    links:
    - redis
  redis:
    image: redis
volumes:
  logvolume01: {}

docker-compose up 100个服务

Compose重要概念:

  • 服务service,容器,应用(web redis mysql)
  • 项目project。一组关联的容器,博客,web,mysql
  1. 安装Compose

    1. 通过官网:
      https://docs.docker.com/compose/install/
    2. 参考:
      https://blog.csdn.net/fxbin123/article/details/104941460/
  2. 体验一把
    https://docs.docker.com/compose/gettingstarted/

在这里插入图片描述

小结:

  1. Docker镜像 run =》容器
  2. Dockerfile构建镜像(服务打包)
  3. docker-compose 启动项目(编排、多个微服务环境)
  4. Docker网络

yaml规则
docker-compose.yaml(核心)

3层:

version: 版本
service: 服务
web: 服务1
# 服务配置
images
build
network

redis: 服务2

服务3

#其他配置 网络、卷、全局规则
volumes:
networks:
configs:

  1. 官方文档
    https://docs.docker.com/compose/compose-file/#expose

  2. 开源项目compose.yaml

开源项目:
博客

compose 应用 =>一键启动!

  1. 下载项目(docker-compose.yaml)
  2. 如果需要文件 Dockerfile
  3. 文件准备齐全(直接一键启动项目)

不加 -d 前台启动

docker -d 后台启动
开启:
docker-compose up -d
停止:
docker-compose down

掌握:docker 基础,原理,网络,服务,集群,错误排查,日志
linux docker k8s

实战:计数器

  1. 编写项目微服务
  2. Dockerfile构建镜像demo
  3. docker-compose.yaml 编排项目
  4. 丢到服务器 docker-compose up
假设项目要重新部署打包,使用如下命令,即重新构建
docker-compose up --build

小结:
未来项目只要有docker-compose 文件,按照这个规则,启动编排容器
公司:docker-compose 直接启动
网上开源项目:docker-compose 一键搞定

总结:
工程 服务 容器
项目compose :三层

  • 工程
  • 服务
  • 容器 运行实例 ! docker k8s 容器
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值