• Docker


    Docker Compose简介

    Docker 提供的一个命令行工具,用来定义和运行由多个容器组成的应用,可以轻松、高效的统一管理多个容器。

    使用一个 Dockerfile 模板文件,可以让用户很方便的定义一个单独的应用容器。
    然而,在日常工作中,经常会碰到需要多个容器相互配合来完成某项任务的情况。
    Compose 允许用户通过一个单独的 docker-compose.yml 模板文件(YAML 格式)来定义一组相关联的应用容器为一个项目(project),并由单个命令完成应用的创建和启动。

    Compose 项目由 Python 编写,实现上调用了 Docker 服务提供的 API 来对容器进行管理。
    因此,只要所操作的平台支持 Docker API,就可以在其上利用 Compose 来进行编排管理。

    两个概念

    • 服务 (service):一个应用的容器,实际上可以包括若干运行相同镜像的容器实例。
    • 项目 (project):由一组关联的应用容器组成的一个完整业务单元,在 docker-compose.yml 文件中定义,通过子命令对项目中的一组容器进行便捷地生命周期管理。
      可见,一个项目可以由多个服务(容器)关联而成,Compose 面向项目进行管理,也就是说Compose 的默认管理对象是项目。

    三个步骤

    1. 使用 Dockerfile 定义应用程序的环境。
    2. 使用 docker-compose.yml 定义构成应用程序的服务,这样它们可以在隔离环境中一起运行。
    3. 最后,执行 docker-compose up 命令来启动并运行整个应用程序。

    安装docker-compose

    官方步骤:https://docs.docker.com/compose/install/#install-compose

    示例:Linux OS

    # 下载docker-compose
    $ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    
    # 授权
    $ sudo chmod +x /usr/local/bin/docker-compose
    
    # 版本信息显示正常说明安装成功
    $ docker-compose --version
    

    docker-compose命令说明

    [root@anliven ~]# docker-compose --version
    docker-compose version 1.26.0, build d4451659
    [root@anliven ~]#
    [root@anliven ~]# docker-compose --help
    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)
      -c, --context NAME          Specify a context name
      --verbose                   Show more output
      --log-level LEVEL           Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
      --no-ansi                   Do not print ANSI control characters
      -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
      --project-directory PATH    Specify an alternate working directory
                                  (default: the path of the Compose file)
      --compatibility             If set, Compose will attempt to convert keys
                                  in v3 files to their non-Swarm equivalent
      --env-file PATH             Specify an alternate environment file
    
    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
      exec               Execute a command in a running container
      help               Get help on a command
      images             List images
      kill               Kill containers
      logs               View output from containers
      pause              Pause services
      port               Print the public port for a port binding
      ps                 List containers
      pull               Pull service images
      push               Push 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
      top                Display the running processes
      unpause            Unpause services
      up                 Create and start containers
      version            Show the Docker-Compose version information
    [root@anliven ~]#
    

    docker-compose模板文件

    参考消息


    Action is the antidote to despair!

    欢迎转载和引用,但请在明显处保留原文链接和原作者信息!
    本博客内容多为个人工作与学习的记录,少部分内容来自于网络并略有修改,已尽力标明原文链接和转载说明。如有冒犯,即刻删除!

    以所舍,求所获,有所依,方所成。
  • 相关阅读:
    MySQL、Redis 和 MongoDB 的优缺点
    解决数据库高并发
    数据库事务
    Mysql 数据库存储的原理?
    CSRF
    MVC模型和MVT模型
    AJAX
    正则表达式-re模块
    ddt-数据驱动测试
    python-时间格式化
  • 原文地址:https://www.cnblogs.com/anliven/p/12110081.html
Copyright © 2020-2023  润新知