docker starts nacos (stand-alone mode, cluster mode)

1. Pull the nacos image

docker pull nacos/nacos-server:v2.1.2

2. Copy the files in the nacos container to the host for mounting

2.1. Run nacos in stand-alone mode first

docker run -d --name nacos -p 8848:8848 -e MODE=standalone nacos/nacos-server:v2.1.2
Check the running process: docker logs -f nacos

ps: If the startup fails, the server memory may be too small. If you want to limit the memory size occupied by nacos, use the following statement

docker run --name nacos -e JVM_XMS=256m -e JVM_XMX=256m -e MODE=standalone -p 8848:8848 -d nacos/nacos-server:v2.1.2 You
can also modify the memory size of the container after installation:
docker stop nacos
docker update -m 256M --memory-swap 512M nacos-quick
docker start nacos

2.2. Copy the nacos file to the /app directory on the host

docker cp nacos:/home/nacos /usr/local
ps: The default storage location of nacos in docker is /home/nacos

2.3. Delete nacos container

docker rm -f nacos

3. Create nacos database

Find the mysql-schema.sql file under /usr/local/nacos/config, copy the content inside and run it in mysql, and then the data table will be automatically generated
insert image description here

4. Run nacos

4.1. Run nacos in stand-alone mode and use mysql to store information

docker run -d --name nacos \
-p 8848:8848 \
-p 9848:9848 \
-p 9849:9849 \
–restart always \
-v /usr/local/nacos/logs:/home/nacos/logs\
-; v /usr/local/nacos/data:/home/nacos/data \
-v /usr/local/nacos/config:/home/nacos/config \ -e
MODE=standalone \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST =Default port ip \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_DB_NAME=nacos \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=default password \
nacos/nacos-server:v2.1.2

View the running process: docker logs -f nacos
insert image description here

4.2. Run nacos in cluster mode and use mysql to store information

nacos1

docker run -d --name nacos-cluster \
-p 8848:8848 \
-p 9848:9848 \
-p 9849:9849 \ (9848, 9849 are new ports for nacos2.X, if not added, the SpringBoot service will fail to register )
–net host \ (change from bridge mode to host mode, use the host’s ip address, otherwise the registration service may go wrong)
–restart always \ (two dashes in front, remember to modify)
-v /usr/local/nacos /logs:/home/nacos/logs \
-v /usr/local/nacos/data:/home/nacos/data \
-v /usr/local/nacos/config:/home/nacos/config \
-e MODE= cluster \
-e NACOS_SERVERS=192.168.137.133:8848 \ (here is the ip address pointing to other cluster services, if there are multiple ip, use single quotes)
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.137.134 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_DB_NAME=nacos \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=database password \
-e TZ=Asia/Shanghai \ (errors may be reported when registering the service without adding time)
nacos/nacos-server:v2.1.2

nacos2

docker run -d --name nacos-cluster \
-p 8848:8848 \
-p 9848:9848 \
-p 9849:9849 \ (9848, 9849 are new ports for nacos2.X, if not added, the SpringBoot service will fail to register )
–net host \ (change from bridge mode to host mode, use the host’s ip address, otherwise the registration service may go wrong)
–restart always \ (two dashes in front, remember to modify)
-v /usr/local/nacos /logs:/home/nacos/logs \
-v /usr/local/nacos/data:/home/nacos/data \
-v /usr/local/nacos/config:/home/nacos/config \
-e MODE= cluster \
-e NACOS_SERVERS=192.168.137.134:8848 \ (here is the ip address pointing to other cluster services, if there are multiple ip, use single quotes)
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.137.134 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_DB_NAME=nacos \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=database password \
-e TZ=Asia/Shanghai \ (errors may be reported when registering the service without adding time)
nacos/nacos-server:v2.1.2

Follow-up to be added. . .

Guess you like

Origin blog.csdn.net/RuserTion/article/details/128186190