Docker compose one click deployment of distributed configuration center Apollo

Posted by michibk on Thu, 23 Sep 2021 07:34:26 +0200

brief introduction

When talking about distributed, we must think of distributed configuration center, distributed log, distributed link tracking, etc

In distributed deployment, businesses often have many configurations. For example, applications need to read some configuration information during startup and operation. Configuration basically accompanies the whole life cycle of applications, such as database connection parameters and startup parameters, which need to be maintained and configured, but it is impossible to log in to configure one server at a time
Today, I want to share with you the distributed configuration center Apollo:

Apollo (Apollo) is a distributed configuration center developed by Ctrip framework department. It can centrally manage the configuration of different application environments and clusters. After the configuration is modified, it can be pushed to the application end in real time. It also has standardized permissions, process governance and other characteristics. It is suitable for micro service configuration management scenarios.


There are two building methods in the official documents. One is to download the source code and the other is to use Docker or K8S. Today we use Docker to build. After all, Docker is more friendly to developers.

If Mysql service is available, it is recommended to use Mysql service or cloud service RDS as the database. After all, the data is priceless.

version: "3"
  apollo-configservice: #Config Service provides functions such as reading and pushing configuration, and the service object is the Apollo client
    image: apolloconfig/apollo-configservice:1.8.1
    restart: always
    #container_name: apollo-configservice
          - ./logs/apollo-configservice:/opt/logs
      - "8080:8080"
      - TZ='Asia/Shanghai'    
      - SERVER_PORT=8080
      - SPRING_DATASOURCE_URL=jdbc:mysql://
  apollo-adminservice: #Admin Service provides configuration modification, publishing and other functions. The service object is Apollo Portal (Management Interface)
    image: apolloconfig/apollo-adminservice:1.8.1
    restart: always
    #container_name: apollo-adminservice
      - ./logs/apollo-adminservice:/opt/logs
      - "8090:8090"
      - apollo-configservice
      - TZ='Asia/Shanghai'    
      - SERVER_PORT=8090
      - SPRING_DATASOURCE_URL=jdbc:mysql://
  apollo-portal: #Management interface
    image: apolloconfig/apollo-portal:1.8.1
    restart: always
    container_name: apollo-portal
      - ./logs/apollo-portal:/opt/logs
      - "8070:8070"
      - apollo-adminservice
      - TZ='Asia/Shanghai'    
      - SERVER_PORT=8070
      - DEV_META=
      - SPRING_DATASOURCE_URL=jdbc:mysql://

As can be seen from the above docker-compose.yaml, there are three services, namely:

  1. Config Service provides functions such as reading and pushing configuration, and the service object is the Apollo client

  2. Admin Service provides configuration modification, publishing and other functions. The service object is Apollo Portal (Management Interface)

  3. Portal (administration interface)
    If you want to know how they work, it is recommended to check the official documents

The logs are mounted to the external. / logs directory

You can see that the deployment of Mysql is not given above. If you need to deploy Mysql using a container, please refer to docker-compose.yaml below

version: '3'


  mysql: # myslq database
    image: 'mysql/mysql-server'
    container_name: 'mysql'
    restart: always
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --lower-case-table-names=1
    environment: #environment variable
      MYSQL_ROOT_HOST: "%" 
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USER: brook
      MYSQL_PASSWORD: password
      - "3306:3306"

The above mysql docker-compose.yaml is only for testing

Initialize database

[apolloconfigdb.sql]( )And [Apollo PORTALDB. SQL]( )

After the database is initialized, remember to modify eureka.service.url of the serverconfig table in the Apollo config DB library, otherwise the Apollo admin service cannot be registered with Eureka

After modification, switch to the Apollo docker-compose.yaml directory and use

docker-compose up -d #Start the three services in the file and run in the background

View startup

docker-compose ps

visit #Apollo management end

Default user name: apollo
Default password: admin

Create a test project


Create a. NetCore project and add client

Add Apollo

Configure Apollo

Configuration above

Add test content
Get Apollo in code

Initiator request / weatherforecast / Apollo test

It was found that the configuration set in apollo was not obtained

Check Apollo and find that the configured value is not published

So if you configure or modify Apollo, you must remember to publish it. After publishing, we refresh the browser again

It is found that the data is new. Let's modify the Value of Apollo again


To this end, Apollo has been built and can be used normally


The code in the example is

Welcome to Start

Note: if the configuration cannot be pulled after the program is started, you can open the Apollo log, see the detailed configuration in the console, and put it in the first line of the Program.cs Main function!


reference resources


Topics: ASP.NET Docker docker compose apollo