Nacos series (1) docker install stand-alone nacos service

Article Directory

I. Overview

In 2018, Alibaba will open source Nacos. Nacos is the name after the open source. It is based on the core code integration of Alibaba's internal Configserver (registration center), Diamond (persistent configuration center), and Vipserver (a registry similar to Configserver that provides routing information) , The goal is to create the world's most powerful service registration and configuration center.

This article simply deploys a nacos service for an intuitive understanding.

2. Deployment steps

Since it is installed using docker, this article will not introduce the use of docker, you can refer to: docker use

2.1 Download the demo file

Nacos provides a demo configuration file on github, download it first:

git clone
cd nacos-docker

There are files as follows: the

Insert picture description here

key is the env and example files.

2.2 Install and start

Start command:

#注意最后的-d 表示后台启动,不加-d启动后可能无法访问控制台
docker-compose -f example/standalone-mysql-5.7.yaml up -d

Since nacos itself does not have a storage function, it needs to be used with a database. Here we use mysql5.7. By default, derby, mysql5.7, and mysql8 are supported, and the corresponding yaml configuration file is in the example path.

Example file description:

  • standalone-mysql-5.7.yaml: standalone mode, using mysql5.7 database
  • standalone-mysql-8.yaml: standalone mode, using mysql8 database
  • standalone-derby.yaml: standalone mode, using the embedded Derby database
  • cluster-hostname.yaml: cluster mode, using mysql5.7 database
  • cluster-embedded.yaml: cluster mode, using embedded derby database

Note before starting, MySQL uses port 3306 by default, then when your server has installed mysql and occupies 3306, it will fail to start. At this time, you can modify the nacos configuration to use your locally installed mysql,
or you can modify it directly The mapped port of mysql, and then start,
modify the mysql ports in the standalone-mysql-5.7.yaml file as follows:

version: "2"
    image: nacos/nacos-server:${NACOS_VERSION}
    container_name: nacos-standalone-mysql
      - ../env/nacos-standlone-mysql.env
      - ./standalone-logs/:/home/nacos/logs
      - ./init.d/
      - "8848:8848"
      - "9848:9848"
      - "9555:9555"
      - mysql
    restart: on-failure
    container_name: mysql
    image: nacos/nacos-mysql:5.7
      - ../env/mysql.env
      - ./mysql:/var/lib/mysql
    # 将mysql的端口改为3307,避免冲突
      - "3307:3306"
#  prometheus:
#    container_name: prometheus
#    image: prom/prometheus:latest
#    volumes:
#      - ./prometheus/prometheus-standalone.yaml:/etc/prometheus/prometheus.yml
#    ports:
#      - "9090:9090"
#    depends_on:
#      - nacos
#    restart: on-failure
#  grafana:
#    container_name: grafana
#    image: grafana/grafana:latest
#    ports:
#      - 3000:3000
#    restart: on-failure

View container

docker ps
Insert picture description here

2.3 Nacos console

username/password: nacos/nacos

The interface after login is as follows:

Insert picture description here

because it is the registration center + configuration center, the main menu is configuration management + service management.

By default, they are all empty. We can use the following commands to simply register and add configuration.

2.4 Service registration and discovery


# 随便注册一个服务,参数:服务名、ip、port
curl -X POST ''

Then go to the service list to check and find that the registration is successful:

Insert picture description here


curl -X GET ''


{"name":"[email protected]@nacos.naming.serviceName","groupName":"DEFAULT_GROUP","clusters":"","cacheMillis":10000,"hosts":[{"instanceId":"[email protected]@nacos.naming.serviceName","ip":"","port":8080,"weight":1.0,"healthy":false,"enabled":true,"ephemeral":true,"clusterName":"DEFAULT","serviceName":"[email protected]@nacos.naming.serviceName","metadata":{},"instanceHeartBeatInterval":5000,"instanceIdGenerator":"simple","instanceHeartBeatTimeOut":15000,"ipDeleteTimeout":30000},{"instanceId":"[email protected]@nacos.naming.serviceName","ip":"","port":8080,"weight":1.0,"healthy":true,"enabled":true,"ephemeral":true,"clusterName":"DEFAULT","serviceName":"[email protected]@nacos.naming.serviceName","metadata":{},"instanceHeartBeatInterval":5000,"instanceIdGenerator":"simple","instanceHeartBeatTimeOut":15000,"ipDeleteTimeout":30000}],"lastRefTime":1622882336296,"checksum":"","allIPs":false,"reachProtectionThreshold":false,"valid":true}

2.5 Configuration release and acquisition

Add configuration:
add a configuration at will:
mainly configure data id, group, and content:

Insert picture description here

but to view this data in the mysql database:

Insert picture description here

you can also call the interface:

# 参数:dataId、group、content
curl -X POST ""

This article will stop here first.