Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

# IT star is not a dream # [1 key deployment Shenggong] docker-compos

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Docker is an open source application container engine that packages applications and dependencies into a portable image, deploys to a server and runs in a container container instance.

Resource orchestration Docker-compose defines and runs an application system composed of multiple containers, declares each service through the docker-compose.yml file, and completes the creation and startup of the application as a whole.

Swarm is an official cluster management tool provided by Docker, which unifies the management of Docker nodes, takes service service as the scheduling unit, and supports dynamic expansion and other features.

Ali Cloud Container Image Service provides Docker image repository hosting, configures project code Git repository and construction rules, and easily implements the automatic construction system of Docker image.

Jext technology community open source Web service scaffolding, collate and sublimate from actual projects, and expand development for a variety of business scenarios. The system deployment process and automatic build system are shown below:

Content catalog:

1. System architecture

2. Deploy the development environment with one click of docker-compose

3. Dockerfile configuration

4. Aliyun + Git+Docker Image automatic Construction system

5. Docker-compose deploy Web service with one click

6. Swarm cluster deployment Web service

7. Selection of Docker container orchestration, mirroring services and Git code hosting cloud services

First, system architecture

L code download

Https://github.com/jextop/StarterDeploy

Https://github.com/jextop/StarterApi/

Https://github.com/jextop/StarterAdmin

L function module

Web service scaffolding is based on SpringBoot development, front and back end dynamic and static separation architecture, provides REST interface and WebAdmin management backend, distributed asynchronous task scheduling, integrated cache, message queue, ELK log processing and service monitoring system, deployed by Docker container, supports cluster expansion, and can meet the expansion and custom development of a variety of business scenarios.

N WebAdmin Management backend

Technology stack: JavaScript, Umi, React, AntDesign Pro

N API interface service

Technology stack: Java, SpringBoot, Flyway, MySQL, MyBatis, Redis, ActiveMQ, Quartz

N business processing service

Receive the business request from the middle station, process the business logic asynchronously, and send a notification message after the processing is finished.

Technology stack: Python,Django,Celery, Redis, ActiveMQ

L sequence diagram

Second, docker-compose one-click deployment of the development environment

L development and running environment

L configuration files and auxiliary scripts: StarterApi

├── docker-compose.yml

├── pull.sh

├── up.sh

├── logs.sh

├── down.sh

Docker-compose.yml configures container instances of the development environment: databases, caches, message queues, ELK logs, and service monitoring systems.

Db_admin needs to connect to MySQL,logstash and kibana needs to connect to elasticsearch, so the depends_on property is set.

Logstash and kibana add configuration files to the basic image, and the generated image is hosted in Aliyun:

Https://github.com/rickding/HelloDocker/tree/master/logstash

Https://github.com/rickding/HelloDocker/tree/master/kibana

Version:'3'

Services:

Db:

Hostname: db

Image: mysql:5

Command:-- default-authentication-plugin=mysql_native_password

Ports:

-3306 3306

Environment:

MYSQL_DATABASE: starter

MYSQL_ROOT_PASSWORD: root

Db_admin:

Image: adminer:latest

Ports:

-3006 purl 8080

Depends_on:

-db

Cache:

Hostname: cache

Image: redis:4

Command: redis-server-- appendonly yes

Ports:

-6379PUR 6379

Mq:

Hostname: mq

Image: webcenter/activemq:latest

Ports:

-61616purl

-8161 Phantom 8161

Elasticsearch:

Hostname: elasticsearch

Image: elasticsearch:latest

Ports:

-9200 purl 9200

-9300 purl 9300

Log:

Hostname: log

Image: registry.cn-shanghai.aliyuncs.com/hellodock/logstash:latest

Ports:

-9600 purl 9600

-9601 Freund 9601

Depends_on:

-elasticsearch

Kibana:

Image: registry.cn-shanghai.aliyuncs.com/hellodock/kibana:latest

Ports:

-5601 Fraser 5601

Depends_on:

-elasticsearch

L run. / pull.sh to pull the image

You can directly run docker pull mysql:5 to pull the image, and run docker images to view the downloaded image:

Run. / up.sh to start the container

The docker-compose up-d command is encapsulated in the script. After startup, run docker ps to view the container instance:

L run. / logs.sh to view the log

Custom commands highlight important information:

Docker-compose logs-ft | grep-- color-I-e error-e warn-e version-e exception

L run. / down.sh to stop the service

Docker-compose down-- remove-orphans stops and deletes the container:

L View Services

Using docker-compose to deploy the development environment MySQL+Redis+ActiveMQ+ELK with one click is as simple as wayward.

Db_admin

ActiveMQ

Elasticsearch

Logstsh

Kibana

Third, Dockerfile configuration is the core of building Docker image.

The Dockerfile image description file contains instructions, each of which builds a layer, so the content of each instruction is to describe how the layer should be built. Basic structure of Dockerfile:

-basic image

-maintainer information

-Image build instruction

-execute instructions when the container starts

FROM openjdk:8

LABEL maintainer= "Jext Community, https://github.com/jextop"

# copy files

COPY. / deploy/ / deploy

WORKDIR / deploy

# do sth

CMD ["sh", "launch.sh"]

EXPOSE 8011

Build an API service Docker image: StarterApi

├── Dockerfile

├── Dockerfile_ce

-Dockerfile_ce, known as the community version, relies on the local development environment and packages the compiled project run files into the Docker image, which is mostly used for local development testing.

-Dockerfile, starting with pulling the source code, compiling and generating the project run file, packaging it into the Docker image, and then releasing the deployment. The automatic construction system of Docker image is based on Dockerfile.

Question and answer:

What's the difference between Dockerfile_ce and Dockerfile?

The project run files used by the build image come from different sources. Dockerfile_ce is mostly used for development testing, packaging run files that are compiled using the local development environment. Dockerfile compiles the project run file from the source code, does not depend on the local environment, and is often built slowly, which is used for release and deployment.

Why is RUN sh mvnw package used in Dockerfile? What is the difference between mvnw and mvn?

Resolve Maven version and plug-in compatibility issues. Mvnw full name MavenWrapper, is a third-party Maven plug-in for the SpringBoot project to provide a separate and specified version of Maven, does not affect the global version and other projects, has been automatically installed when the SpringBoot project is generated.

There are two files mvnw and mvnw.cmd under the SpringBoot project, and three files under a .mvn directory.

Spring-boot-project

├── .mvn

│ └── wrapper

│ ├── maven-wrapper.jar

│ └── maven-wrapper.properties

│ ├── MavenWrapperDownloader.java

├── mvnw

├── mvnw.cmd

Fourth, Aliyun + Git+Docker image automatic construction system

Ali Cloud Container Image Service provides Docker image repository hosting, configures project code Git repository and construction rules, and implements cloud compilation and packaging with Dockerfile, eliminating the need for commonly used Jenkins build servers.

Add a latest build rule for the master branch and configure the options in turn:

-Type: select Branch

-Branch: select master

-Dockerfile directory: /

-Dockerfile file name: Dockerfile

-Image version: latest

After the configuration is complete, the build is automatically triggered when code is submitted to the Git repository. Click "build now" of the rule to manually trigger, and click "Log" of the build list to view process information.

Fifth, docker-compose deploys Web service with one click

After the API API service Docker image is successful, the configuration information will be sent to the docker-compose.yml:

Code base StarterDeploy

├── docker-compose.yml

├── up.sh

├── logs.sh

# omit the container configuration of the running environment in the file, and the following is the API service Docker image automatically generated by the system

Api:

Hostname: api

Image: registry.cn-shanghai.aliyuncs.com/jext/starter_api:latest

Ports:

-8011 Phantom 8011

Depends_on:

-db

-cache

-mq

-log

Run the. / up.sh deployment task, and then run. / logs.sh to see the interface service startup information developed by SpringBoot:

Visit http://localhost:8011/chk to see the service self-test information:

Sixth, Swarm cluster deploys Web service

Code base: StarterDeploy

├── docker-compose.yml

├── deploy.sh

├── rm.sh

L docker-compose.yml adds deploy attribute, replicas specifies the number of copies, and placement specifies docker node:

Deploy:

Replicas: 1

Placement:

Constraints: [node.labels.group = = api]

L start Swarm to join the node to build a cluster, and the first node automatically becomes the administrator: docker swarm init

Deploy Web service: execute script. / deploy.sh or command: docker stack deploy-c docker-compose.yml starter

L View Stack and services: docker stack ls & & docker service ls

L stop deletion service: execute script. / rm.sh or command: docker stack rm starter

Seventh, the choice of Docker container orchestration, mirroring service and Git code hosting cloud service

When building a system to select cloud services, we focus on the integration efficiency and stability of system deployment, operation and maintenance, automatic construction and code management. Several major cloud service providers are compared and information is sorted out and shared in no particular order. The information is updated on January 16, 2020.

Container services (resource orchestration)

Mirror service

Code hosting

Ali Yun

Charge for computing resources used

Public test, free of charge, http://cr.console.aliyun.com/

Each user can build 50 code bases with a single database capacity of 2G

Https://code.aliyun.com/

Huawei Cloud

Charge, buy the package.

Free of charge

Https://cn-east-3-console.huaweicloud.com/swr

0.11 yuan / user / hour, 0.000442 yuan / GB/ hour

Https://console.huaweicloud.com/devcloud/?region=cn-east-3#/codehub/list

Tencent Cloud

Charge for computing resources used

Internal test, need to apply

Https://cloud.tencent.com/product/tcr/

Official website: the charge is expected to start in January 20, 1 yuan per person / day

Https://console.cloud.tencent.com/coding

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report