05.Docker Compose 下载安装

一、安装

1.下载

https://docs.docker.com/compose/install/

01

官网地址

sudo curl -L "https://github.com/docker/compose/releases/download/1.28.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

加速地址(修改版本号:地址)

curl -L https://get.daocloud.io/docker/compose/releases/download/1.28.3/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

02

2.授权

sudo chmod +x /usr/local/bin/docker-compose

04

3.官网快速开始跑一次:官网

1)创建文件夹并进入

mkdir composetest
cd composetest

2)创建一个Python应用的web项目,文件名为“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:
            if retries == 0:
                raise exc
            retries -= 1
            time.sleep(0.5)

@app.route('/')
def hello():
    count = get_hit_count()
    return 'Hello World! I have been seen {} times.\n'.format(count)

3)创建依赖引入文件“requirements.txt”

flask
redis

4)创建"Dockerfile"

FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["flask", "run"]

5)创建“docker-compose.yml”

version: "3.9"
services:
  web:
    build: .
    ports:
      - "5000:5000"
  redis:
    image: "redis:alpine"

05

6)启动(注:要在有docker-compose.yml文件夹下启动)

docker-compose up

启动docker-compose前创建了一个网络

07

我们可以查看网络

06













(1)