docker compose
Docker compose
https://docs.docker.com/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.
docker命令只能构建和运行一个容器。
但是容器一般只建议运行一个服务,一般应用后台依赖若干个服务,例如数据库、web服务器。
一起维护同一个应用的若干容器,就成为一件麻烦的事情。
docker compose的诞生就是为了解决这个问题。
Usage
容器的构建,还是使用dockerfile
容器组合的定义使用新的配置文件 docker-compose.yml, 配置文件支持公共配置定义 和 定制配置覆盖。
Using Compose is basically a three-step process:
Define your app’s environment with a
Dockerfile
so it can be reproduced anywhere.Define the services that make up your app in
docker-compose.yml
so they can be run together in an isolated environment.Run
docker-compose up
and Compose starts and runs your entire app.A
docker-compose.yml
looks like this:version: '3' services: web: build: . ports: - "5000:5000" volumes: - .:/code - logvolume01:/var/log links: - redis redis: image: redis volumes: logvolume01: {}
For more information about the Compose file, see the Compose 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
功能
The features of Compose that make it effective are:
1) 多个独立环境在单机上运行。
--- 我理解应该是 docker的功能。
2)当容器被创建时候保留数据。
--- 我理解应该是 docker的功能。
3)只重新创建改变的容器,即dockerfile有改变,才重新构建新的容器。
--- 这是docker compose的新功能。
4)变量支持 + 在不同的环境中移动组合。
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.
---- docker-compse.yml 配置文件可以感知系统的环境变量, 和此工具自己定义的变量(在.env文件中), 以及在此配种自己定义变量。
这就促使其拥有跨环境的感知能力, 应对生产环境、测试环境、开发环境的改变。
为什么需要这个功能, 我理解不同环境下,软件定义的行为是略有差异, 例如开发环境下, 所有打印全开, 生产环境下值开启 critical级别打印。
使用场景
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.
Development environments
让开发者使用一个命令就可以启动完整的应用,
docker-compose up
此阶段不考虑后台应用的复杂化架构和部署, 例如 高可用 高并发, 需要依赖 代理服务器 和 副本策略。
Automated testing environments
对于功能测试, 需要快速启动测试环境下的应用, 然后运行测试脚本,和拆除测试环境。
使用docker-compose只需要三个命令:
$ docker-compose up -d
$ ./run_tests
$ docker-compose down
Single host deployments
在生产环境下,也可以使用此工具,应对生产环境下的单机部署。
此功能应对简单应用的部署, 不过大型应用, 会借助 kubernetes mesos 做分布式部署。
相关文章
- DockerToolbox安装docker - Windows 10
- docker-compose的安装
- docker-compose搭建wordpress
- docker-compose编排springcloud微服务
- docker的编排- docker -compose(了解)
- docker 报Error: docker-engine-selinux conflicts with docker-selinux-1.9.1-25.el7.centos.x86_64
- DaemonSet 案例分析 - 每天5分钟玩转 Docker 容器技术(130)
- docker配置阿里云的仓库源以及安装docker-compose
- Docker 实战(2)- 在 Jenkins 容器上的搭建持续集成环境和完成自动化测试
- Docker(26)- docker tag 命令详解
- Docker-compose command 有多个命令例子
- Docker 容器跨主机多网段通信解决方案
- 使用Docker和Golang进行便捷的MongoDB测试
- 如何用Gradle创建Docker镜像
- Spring Boot与Docker(四):额外的微服务、更新容器、Docker Compose和负载均衡
- Docker 使用docker-compose构建WordPress博客
- Linux CentOS Docker 安装与配置
- PWD简介与妙用(一个免费、随时可用的Docker实验室)
- docker compose fullstack example
- halo搭建炫酷个人博客快速部署:docker+docker-compose+nginx
- Docker安装Kafka(docker-compose)、EFAK监控
- Docker Compose实例
- docker compose示例
- 构建Docker Compose服务堆栈
- Docker Compose 安装 MySQL