Table of Contents
Docker container orchestration
What is container orchestration
Case:
Container orchestration application question 1
Home Operation and Maintenance Docker What is docker container orchestration

What is docker container orchestration

Dec 30, 2021 pm 04:24 PM
docker Container orchestration

In docker, by executing a YAML file, multiple containers defined in the file are started in sequence. This is container orchestration; the tool for implementing container orchestration is "docker-compose". The YAML file defines a series of containers and container runtime properties, and Compose will manage the container based on these configurations.

What is docker container orchestration

The operating environment of this tutorial: linux5.9.8 system, docker-1.13.1 version, Dell G3 computer.

Docker container orchestration

What is container orchestration
  • By executing a file, multiple containers defined in the file are started in sequence , this is container orchestration
  • This file is the yaml file

The tool used to implement container orchestration

  • docker-compose

    You can install the Docker Compose tool to implement container orchestration based on YAML files. The YAML file will define a series of containers and container runtime attributes, and Docker Compose will manage the containers based on these configurations.

Install docker-compose

  • docker-compose in epel source
[root@worker1 ~]# yum install epel-release -y
[root@worker1 ~]# yum install docker-compose -y
Copy after login

Usage of docker-compose command

  • Format: docker-compose [options]

  • options

    • up: Start the container defined in the yaml file
    • down: Close the container defined in the yaml file
    • -f x.yaml: Specify docker-compose to read yaml file
    • -d: Perform operations in the background
    • ps: Check the status of the container started based on docker-compose
    • logs: Check the logs during the process of starting the container Information for troubleshooting errors
Case:

Write the docker-compose.yaml file to start two containers : nginx, php

1) Prepare the environment

  • Install epel
  • Install docker-compose
  • Restart docker
  • Restart the firewall
[root@master ~]# yum install docker -y
[root@master ~]# yum install epel-release -y
[root@master ~]# yum install docker-compose -y
[root@master ~]# systemctl restart docker
[root@master ~]# systemctl restart firewalld
Copy after login

2) Create a yaml file

# 编写yam文件,在文件实现自动启动nginx容器
[root@worker1 ~]# vim docker-compose.yaml
Copy after login
version: '2'
services:
  web:
    image: nginx:1.17.10
    ports:
      - 80:80
    volumes:
      - /opt/html:/web
      - /opt/conf/nginx.conf:/etc/nginx/nginx.conf
Copy after login
  • version: specify the version number, 2
  • services: Set to start the service, a service is a docker container

2) nginx starts the container

[root@worker1 ~]# docker-compose up -d
Copy after login

View based on yaml The status of the container started by the file

[root@master ~]# docker-compose ps
   Name            Command          State         Ports       
--------------------------------------------------------------
root_web_1   nginx -g daemon off;   Up      0.0.0.0:80->80/tcp
Copy after login
  • The status is mainly state: if it is UP, it means normal

View the log during the process of starting the container Information

[root@worker1 ~]# docker-compose logs
Copy after login

Close the container started based on the yaml file

[root@worker1 ~]# docker-compose down
Copy after login

3) Edit the yaml file based on the second step and start php Service

The first step: modify the yaml file

version: '2'services:
  web:
    image: nginx
    ports:
      - 80:80
    volumes:
      - /opt/html:/web
      - /opt/conf/nginx.conf:/etc/nginx/nginx.conf
    links:               # 指定php容器的名称
      - php
  php:                   # 此处需要和links中的值保持一致
    image: php:5.6-fpm
    container_name: php   # 此处需要和links中的值保持一致
    volumes:
      - /opt/php:/php
Copy after login

The second step: modify the nginx configuration file

[root@master ~]# vi /opt/conf/nginx.conf 
        location ~ \.php$ {
            root           /php;
            fastcgi_pass   php:9000;    # 指定php容器名称,docker会自动将名称转换成ip
            fastcgi_index  index.php;     
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
Copy after login

Step 3: Start the service

[root@master ~]# docker-compose up -d
[root@master ~]# docker-compose ps
Name         Command                        State         Ports       
-----------------------------------------------------------------------
php          docker-php-entrypoint php-fpm   Up           9000/tcp          
root_web_1   nginx -g daemon off;            Up           0.0.0.0:80->80/tcp
Copy after login

Container orchestration application question 1

1 Prepare a Centos7 server and check that the network is normal

2 Check whether the server docker is running normally. If not, please install it

3 Please write the wordpress.yml template The file is in the correct format

4 Please create new services mysql and wordpress. The startup of wordpress depends on the mysql service

5 Mount the /opt/wordpress/data directory to /var/ of the mysql container Under the lib/mysql directory, do persistent storage!

6 MySQL initial information includes: root password, created database, ordinary user, ordinary user's password

7 WordPress database configuration is correct

8 WordPress does port mapping, will Port 80 of wordprss is mapped to port 8000 of the host machine

# 这个yaml文件要启动两个容器
version: '2'
services:
  # 第一个容器:wordpress容器
  wordpress:
    # 指定镜像名称
    image: wordpress
    # 将容器的80端口映射到宿主机的8000
    ports:
      - 8000:80
    # 设置将mysql容器的名称解析程序mysql容器的IP
    links:
      - mysql
    # 设置容器之间依赖关系,设置成必须先启动mysql容器才启动wordpress容器
    depends_on:
      - mysql
  # 第二个容器:MySQL容器
  mysql:
    # 指定镜像名名称是mysql
    image: mysql:5.6
    # 设置容器的名称的是mysql
    container_name: mysql
    # 设置逻辑卷挂载
    volumes: 
      - /opt/wordpress/data:/var/lib/mysql 
    # 设置mysql容器的环境变量
    environment:
      # 设置mysql容器中mysql的root密码为123
      MYSQL_ROOT_PASSWORD: 123
      # 为wordpress创建一个数据库,库名是wordpress
      MYSQL_DATABASE: wp   
      # 创建一个普通用户wp
      MYSQL_USER: wp
      # 为上面的普通用户设置密码是wp
      MYSQL_PASSWORD: wp
Copy after login

9 docker-compose successfully started each container and successfully accessed the wordpress page

[root@master ~]# docker-compose up -d
[root@master ~]# docker ps
Copy after login
  • Browser access: http:/ /ip:8000

Recommended learning: "docker video tutorial"

The above is the detailed content of What is docker container orchestration. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1652
14
PHP Tutorial
1251
29
C# Tutorial
1224
24
How to exit the container by docker How to exit the container by docker Apr 15, 2025 pm 12:15 PM

Four ways to exit Docker container: Use Ctrl D in the container terminal Enter exit command in the container terminal Use docker stop <container_name> Command Use docker kill <container_name> command in the host terminal (force exit)

How to copy files in docker to outside How to copy files in docker to outside Apr 15, 2025 pm 12:12 PM

Methods for copying files to external hosts in Docker: Use the docker cp command: Execute docker cp [Options] <Container Path> <Host Path>. Using data volumes: Create a directory on the host, and use the -v parameter to mount the directory into the container when creating the container to achieve bidirectional file synchronization.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to restart docker How to restart docker Apr 15, 2025 pm 12:06 PM

How to restart the Docker container: get the container ID (docker ps); stop the container (docker stop <container_id>); start the container (docker start <container_id>); verify that the restart is successful (docker ps). Other methods: Docker Compose (docker-compose restart) or Docker API (see Docker documentation).

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to update the image of docker How to update the image of docker Apr 15, 2025 pm 12:03 PM

The steps to update a Docker image are as follows: Pull the latest image tag New image Delete the old image for a specific tag (optional) Restart the container (if needed)

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

See all articles