肥仔学习日记----Docker Compose

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.exceptions.ConnectionError as exc:
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值