Implementation of Docker batch container orchestration

Implementation of Docker batch container orchestration

Introduction

Dockerfile build run is a manual operation of a single container. If a microservice architecture is used, 100+ containers need to be started. How to maintain the dependencies between them?
Docker Compose is used to manage containers easily and efficiently, and define and run multiple containers.

Three steps:

  • Dockerfile
  • Services & docker-compose.yml
  • docker-compose up

First experience

1.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
COPY . .
CMD ["flask", "run"]

2.Service

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)

docker-compose.yml

version: '3'
services:
web:
 build: .
 ports:
- "5000:5000"
 volumes:
- .:/code
 -logvolume01:/var/log
 links:
- redis
redis:
 image: redis
volumes:
logvolume01: {}
docker-compose up
Starting compose-demo_web_1 ... done
Starting compose-demo_redis_1 ... done
Attaching to compose-demo_redis_1, compose-demo_web_1
redis_1 | 1:C 12 Sep 2020 07:34:09.654 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 12 Sep 2020 07:34:09.655 # Redis version=6.0.7, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 12 Sep 2020 07:34:09.655 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 12 Sep 2020 07:34:09.657 * Running mode=standalone, port=6379.
redis_1 | 1:M 12 Sep 2020 07:34:09.657 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 12 Sep 2020 07:34:09.657 # Server initialized
redis_1 | 1:M 12 Sep 2020 07:34:09.658 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1 | 1:M 12 Sep 2020 07:34:09.658 * Loading RDB produced by version 6.0.7
redis_1 | 1:M 12 Sep 2020 07:34:09.658 * RDB age 156 seconds
redis_1 | 1:M 12 Sep 2020 07:34:09.658 * RDB memory usage when created 0.77 Mb
redis_1 | 1:M 12 Sep 2020 07:34:09.658 * DB loaded from disk: 0.000 seconds
web_1 | * Serving Flask app "app.py"
web_1 | * Environment: production
web_1 | WARNING: This is a development server. Do not use it in a production deployment.
web_1 | Use a production WSGI server instead.
web_1 | * Debug mode: off
YML file rulesversion: "1.0" #versionservices: #service listservice1:
    #Service configuration container_name: #Container name depends_on: #Dependency list - depend1
    -depend2
    images: #Mirror-image1
    - image2
    build:. #Build directory network: #Network......
  service2:test2
    ......
volumnes: #Mount directory list networks: #Network list configs: #Other configurations

This is the end of this article about the implementation of Docker batch container orchestration. For more relevant Docker batch container orchestration content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Implementation of Docker Compose container orchestration in IDEA
  • Using Docker data volumes and container orchestration
  • Docker container orchestration tool Compose (Getting Started)
  • Docker series: Using Docker Compose to orchestrate containers
  • Docker data volume container creation and usage analysis
  • Detailed explanation of Docker container data volumes
  • How to generate a docker image and complete container deployment in a spring boot project
  • How to install kibana tokenizer inside docker container
  • Docker container orchestration implementation process analysis

<<:  MySQL Practical Experience of Using Insert Statement

>>:  WeChat applet scroll-view realizes left and right linkage

Recommend

Fabric.js implements DIY postcard function

This article shares the specific code of fabricjs...

How to encapsulate axios request with vue

In fact, it is very simple to encapsulate axios i...

Tutorial on installing Microsoft TrueType fonts on Ubuntu-based distributions

If you open some Microsoft documents with LibreOf...

Vue3.0 project construction and usage process

Table of contents 1. Project construction 2: Dire...

Detailed explanation of react setState

Table of contents Is setState synchronous or asyn...

How to build sonarqube using docker

Table of contents 1. Install Docker 2. Install so...

Detailed explanation of how to use element-plus in Vue3

Table of contents 1. Installation 2. Import in ma...

Creation, constraints and deletion of foreign keys in MySQL

Preface After MySQL version 3.23.44, InnoDB engin...

Docker5 full-featured harbor warehouse construction process

Harbor is an enterprise-level registry server for...

JavaScript immediate execution function usage analysis

We know that in general, a function must be calle...

What does the n after int(n) in MySQL mean?

You may already know that the length 1 of int(1) ...

Win10 + Ubuntu20.04 LTS dual system boot interface beautification

Effect display The built-in boot interface is too...

HTML cellpadding and cellspacing attributes explained in pictures

Cell -- the content of the table Cell margin (tabl...

Implementation of proxy_pass in nginx reverse proxy

The format is simple: proxy_pass URL; The URL inc...

Method for comparing the size of varchar type numbers in MySQL database

Create a test table -- --------------------------...