I. Service orchestration

Service choreography: Batch manages containers according to certain business rules

The application system of microservice architecture generally contains several microservices, and each microservice will deploy multiple instances. If each microservice has to be started and stopped manually, the workload of maintenance will be large.

Like these jobs:

  • From you toDockerfile build imageOr go todockerhubpullimage
  • To create multiplecontainer
  • To manage thiscontainer(Start stop delete)

Use the official service orchestration

Second, the Docker Compose

Docker Compose is a tool for orchestrating multi-container distributed deployments, providing command sets to manage the complete development cycle of containerised applications, including service building, startup and stop

Use steps:

  1. usingDockerfileDefine the run environment image
  2. usedocker-compose.ymlDefine the services that make up the application (startup sequence, relationship, etc.)
  3. rundocker-compose upStart the application

1, install,

If you are using Docker Desktop, there is no need to install Compose as it already includes Docker Compose.

Here is how to install Compose in Linux

#Install to Linux as a compiled binary package
$The curl - https://github.com/docker/compose/releases/download/1.28.6/run.sh > / usr/Llocal/bin/docker-compose

#Example Set the executable permission of a file
$ chmod +x /usr/local/bin/docker-compose

#View version information (either -v or --version)
$ docker-compose --version
$ docker-compose -v
Copy the code

2, unloading

#If the installation is in binary package mode, delete the binary file
rm /usr/local/bin/docker-compose
Copy the code

3, in actual combat

To write the configuration file, create a new docker-comemess. yml file with a fixed name

touch docker-compose.yml
Copy the code

Here I’m going to open it with VSCode and edit it

code docker-compose.yml
Copy the code

Contents of the document:

version: '3'
services: 
  nginx: The service name is user-defined
    image: nginx # nginx specifies that the image will be booted using nginx. You can specify the version of the image. If you do not specify the version, the default is Latest
    ports: Port mapping, the -p parameter, maps port 80 of the host to port 80 of the container
      - 8090: 80
    links: The Jenkins service can be accessed by the current service
      - jenkins
    volumes: # directory mapping, i.e. -v parameter, (host directory: container directory)
      - ~/data/lxf/nginx/conf.d:/etc/nginx/conf.d
  jenkins: The service name is user-defined
    image: jenkins
    expose:  Expose the specified port
      - "8080"
      - "5000"
Copy the code

Create the ~/data/ LXF /nginx/conf.d directory and go to the directory

mkdir -p ~/data/lxf/nginx/conf.d
cd ~/data/lxf/nginx/conf.d
Copy the code

Create a conf file in this directory, such as lxf.conf, with the following contents

server { listen 80; access_log off; location / { proxy_pass http://jenkins:8080; }}Copy the code

Configure the reverse proxy. When accessing port 80, it will reverse proxy to http://jenkins:8080, where Jenkins is the Jenkins specified by links in the docker-comemage. yml file above

In the docker-compose. Yml file directory, use docker-compose to start the container

#-d: Background startup
docker-compse up [-d]
Copy the code

Test access

127.0.0.1:8090 or the local IP address is 8090Copy the code

Three, references,

Docker Compose official documentation