Article directory
点击跳转:Docker安装MySQL、Redis、RabbitMQ、Elasticsearch、Nacos等常见服务全套(质量有保证,内容详情)
This article describes how to use Docker to install the stand-alone version of Nacos, including the stand-alone non-persistent version and the stand-alone persistent version.
1. Docker builds Nacos stand-alone version
Nacos serves as the configuration center for microservices. Whether in development, testing or production, users prefer Nacos to save user configurations, which means Nacos is required to have persistence capabilities. However, the default situation is that the data is saved in the in-memory database Derby, and the data disappears after restarting. Nacos data can be persisted to MySQL by modifying the configuration. The following introduces the stand-alone non-persistent version and the stand-alone persistent version respectively. It is recommended to use the persistent version.
1.1. Single machine non-persistent
Note: If you just want to simply learn how to use it, just use the following command. However, all nacos metadata will be saved inside the container. If the container is migrated, the nacos metadata will no longer exist, so usually we usually save nacos metadata in mysql.
Take nacos version 2.1.1 as an example:
- Pull image
docker pull nacos/nacos-server:v2.1.1
It is not recommended to use the latest version, as there may be unexpected problems.
- Create container
# 用最新版启动nacos容器
docker run -d --name nacos -p 8848:8848 \
-e MODE=standalone \
nacos/nacos-server:v2.1.1
You can also start it directly without pulling the container. Docker will automatically pull the image for us.
如果想要执行的版本请指定版本号
- Enter the interface http://localhost:8848/nacos
Note: The initial account password is nacos. As long as you enter the page, it means the startup is successful.
1.2. Single-machine persistence to MySQL
The persistent version is recommended even for development and test environments!
The steps to build a single machine and persist to the MySQL server are as follows:
-
Start a mysql server, create the nacos database (customizable), and initialize the nacos database with the sql statement source file
-
Consider persistence configuration
Nacos specifies the startup mode, persistence method, which MySQL to connect to, MySQL user name, MySQL password, etc. through the configuration file. Docker exposes these contents that need to be executed by the user through variables. Common variables are as follows:
variable | illustrate |
---|---|
MODE | model. Standalone fixed writingstandalone |
SPRING_DATASOURCE_PLATFORM | Data platform. fixed writemysql |
MYSQL_SERVICE_HOST | Host |
MYSQL_SERVICE_PORT | port. Default value 3306 |
MYSQL_SERVICE_DB_NAME | Name database |
MYSQL_SERVICE_USER | username |
MYSQL_SERVICE_PASSWORD | password |
MYSQL_SERVICE_DB_PARAM | jdbc url connection parameters (can be customized according to the situation, nacos has default values) |
- Organized into the following commands
Users modify the corresponding variable parameter values according to their own environment. My local command is as follows for reference:
docker run -d -p 8848:8848 --name nacos \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.1.3 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_DB_NAME=nacos \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=root \
nacos/nacos-server:v2.1.1
The only thing to note is that MYSQL_SERVICE_HOST
it must be set to the IP address of the host, because it is a connection between different containers (nacos and mysql), so localhost must not be used
- Enter the supervision interface http://localhost:8848/nacos
Just log in with the initial account password which is nacos.
2. References
https://github.com/alibaba/nacos
My article: "How to check which versions of a Docker image.md"
My article: "Docker Setting Domestic Image Source.md"
My article: "Docker Quick Start Practical Tutorial.md"
My article: "Docker installs MySQL, Redis, RabbitMQ, Elasticsearch, Nacos and other common services.md"
My article: "Docker installs Nacos service.md"
My article: "How to modify the file.md in Docker"
My article: "Connection or communication between Docker containers.md"
My article: "How to persist database data with MySQL installed by Docker.md"
My article: "Making Docker Private Repository.md"
My article: "Using the docker-maven-plugin plug-in to build and publish push images to private warehouses.md"
My article: "Resolving Docker's failure to access port 9200 after installing Elasticsearch.md"
Portal: Nanny-style Spring5 source code analysis
Welcome to exchange technology and work life with the author