Dockers Compose
简介
dockerFile bulid run 手动操作,单个容器。
微服务,将会有多个微服务容器!
Docker Compose 来轻松高效管理容器。运行多个容器
官方介绍
定义运行多个容器
YAML file 配置文件
single command 命令
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.
dockerfile 保证了我们的项目可以在任何地方运行
2.Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
services 什么是服务
docker-compose.yml 文件怎么写?
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.
服务service 容器 应用 web redis mysql …
项目project 一组关联的容器 博客 web mysql …
安装
1、下载
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2、授权
sudo chmod +x /usr/local/bin/docker-compose
安装成功
体验一下
第 1 步:设置
定义应用程序依赖项。
为项目创建一个目录:
mkdir composetest
cd composetest
app.py在您的项目目录中创建一个名为的文件并将其粘贴到:
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis