Use Docker-compose to build a Nacos cluster

Download the NACOS cluster environment

Download docker-compose from Nacos 1.4.0: github.com/nacos-group… (I use Nacos version 1.4.0)

Then use Xftp to put the decompressed folder into Linux.

Create a docker – compose. Yml

Note: please delete the comment !!!!!! when writing to docker-comemess. yml

cd /usr/local/myLocal/nacos-docker-master/example

vim docker-compose.yml

#Docker-comemage. yml file contents
#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- start -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --version: '3' services: docker-nacos-server-1: image: nacos/nacos-server container_name: nacos-server-1 ports: - "8848:8848" - "9555:9555" restart: on-failure network_mode: host SPRING_DATASOURCE_PLATFORM: mysql NACOS_SERVERS: 192.168.20.255:8848 192.168.20.255:8849 192.168.20.255:8850 MYSQL_SERVICE_DB_NAME: 192.168.20.255 NACOS_APPLICATION_PORT: 8848 MYSQL_SERVICE_USER: root MYSQL_SERVICE_PASSWORD: admin MYSQL_SERVICE_USER: root MYSQL_SERVICE_PASSWORD: admin JVM_XMS: 256m JVM_XMX: 256m JVM_XMN: 256m volumes: # mount of folders and files - / cluster - logs/nacos1: / home/nacos/logs - / init. D/custom. Properties: / home/nacos/init. D/custom properties docker-nacos-server-2: image: nacos/nacos-server container_name: nacos-server-2 ports: - "8849:8848" restart: on-failure network_mode: host environment: SPRING_DATASOURCE_PLATFORM: mysql NACOS_SERVERS: 192.168.20.255:8848 192.168.20.255:8849 192.168.20.255:8850 NACOS_APPLICATION_PORT: 8849 MYSQL_SERVICE_HOST: 192.168.20.255 MYSQL_SERVICE_DB_NAME: nacos_config MYSQL_SERVICE_USER: root MYSQL_SERVICE_PASSWORD: admin JVM_XMS: 256m JVM_XMX: 256m JVM_XMN: 256m volumes: - ./cluster-logs/nacos2:/home/nacos/logs - ./init.d/custom.properties:/home/nacos/init.d/custom.properties docker-nacos-server-3: image: nacos/nacos-server container_name: nacos-server-3 ports: - "8850:8848" restart: on-failure network_mode: host environment: SPRING_DATASOURCE_PLATFORM: mysql NACOS_SERVERS: 192.168.20.255:8848 192.168.20.255:8849 192.168.20.255:8850 NACOS_APPLICATION_PORT: 8850 MYSQL_SERVICE_HOST: 192.168.20.255 MYSQL_SERVICE_DB_NAME: nacos_config MYSQL_SERVICE_USER: root MYSQL_SERVICE_PASSWORD: admin JVM_XMS: 256m JVM_XMX: 256m JVM_XMN: 256m volumes: - ./cluster-logs/nacos3:/home/nacos/logs - ./init.d/custom.properties:/home/nacos/init.d/custom.properties
#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - end -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Copy the code

Create the container with docker-comemage.yml

#Go back to the previous directory
cd ..

#Use the -f command to select the specified YML file to create the container 
docker-compose -f example/docker-compose.yml  up -d
Copy the code

test

Visit http://192.168.20.255:8848/nacos, after login to check the list of the nodes in the cluster.

In node metadata, state refers to LEADER and state refers to FOLLOWER.