Docker notes-container orchestration and wordpress deployment practice

What is container orchestration?

For example, the following is a host machine that needs to deploy 3 containers, Nginx service, Tomcat service, and MySQL service. Among them, Nginx provides tomcat with load balancing and reverse proxy functions. Tomcat runs a JavaWeb program. This JavaWeb program depends on MySQL for data access. This group of applications needs to be online. If you manually handle it, you need to start a container to run the MySQL service, then start the Tomcat container, and finally start the Nginx container. And you need to manually set the container configuration file and configure the dependencies between the containers, which is very troublesome. The container orchestration tool can automatically execute the above process by parsing a script file. We only need to write the configuration files needed for container deployment, the relationship between containers, etc., in a script, and the rest can be done automatically for us by the orchestration tool.

Container orchestration is a process of controlling the deployment process of multiple containers.

image-20200523232525680

Docker Compose

Docker Compose is a container orchestration tool officially provided by Docker. It has the following characteristics

  1. Only supports stand-alone
  2. Define how to deploy between multiple containers through yml files
installation
# 先安装docker-compose,下面使用国内镜像
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

# 然后授予权限
sudo chmod +x /usr/local/bin/docker-compose
# 查看是否正确安装
docker-compose -version

image-20200523234010907

The docker-compose installation is successful, let’s start deploying wordpress for practice

Deploy WordPress
# 在宿主机创建目录
mkdir wordpress
# 进入该目录
cd wordpress
# 创建yml文件
vim docker-compose.yml
# yml文件中填写如下信息,下面的信息在docker官方网站的教程上能够找到
# https://docs.docker.com/compose/wordpress/

version: '3.3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {
    
    }
    
# 运行
docker-compose up -d
# 会自动解析刚才创建的docker-compose.yml ,并且以后台进程形式运行

Look at the log, will pull the mysql mirror first

image-20200523234655814

Then, start to pull the wordpress mirror

image-20200523234724201

Finally, you will see 2 containers started

image-20200523234955343

At this point, when the browser accesses port 8000 of the host, you can see that wordpress is successfully built

image-20200523235040146

With the docker network lscommand, you can see that docker-compose automatically creates a bridge for wordpress

image-20200524121414708

Check the detailed information of this bridge, you can see that the two containers of wordpress app and db are bound to this bridge

image-20200524121521969

To turn off the wordpress group of applications, just use docker-compose down. If you start multiple sets of applications with docker-compose and use them directly docker-compose down, how do you know which set of applications is closed ?

The answer is that docker-compose downwhen using it, you must first switch to the directory with the docker-compose.yml configuration file. It will determine which group of applications needs to be closed based on the docker-compose.yml file in the current directory

image-20200524121753108

Another -> can be used docker-compose logsto view the log of the application, but if you view the log in this way, you will see the logs of several applications mixed together. If you want to view the log of an application separately, you can usedocker-compose logs 容器名称

Generally, docker-compose has relatively few applications in the production environment, because it only supports a single machine and does not support clusters. Therefore, in a production environment, container orchestration tools that support clusters are generally used, such as kubernetes

Another -> Now there is a containerized product-podman, which is similar to docker, and can even switch seamlessly with docker commands, but it does not adopt the cs architecture, which seems to be better than docker in some aspects, so you can do a proper understanding

Guess you like

Origin blog.csdn.net/vcj1009784814/article/details/106313465