Docker deploys Nacos

1. Pull the nacos image and start

docker pull nacos/nacos-server

2. Start the nacos command

docker run -d --name nacos -p 8848:8848 -e PREFER_HOST_MODE=hostname -e MODE=standalone nacos/nacos-server

So far, we can use nacos service, UI address: http://:8848/nacos account number: nacos password: nacos

The above method is the easiest way to start, but there is a slight flaw in this case, all the nacos metadata will be stored inside the container. If the container is migrated, the nacos source data will no longer exist, so we usually save the nacos metadata in mysql. The configuration method is attached below:

3. Modify the configuration file

#1 查看docker容器,nacos启动成功
docker ps 
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                    NAMES
8149bca96437        nacos/nacos-server   "bin/docker-startup.…"   4 minutes ago       Up About a minute   0.0.0.0:8848->8848/tcp   nacos
#2 进入容器
docker exec -it 8149bca96437 /bin/bash
#3 修改 conf/application.properties 内容如下:
vi conf/application.properties

Database script

nacos-db.sql

Replace the content of application.properties with

spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://<ip>:<port>/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=password

4. Exit the container

exit

5. Restart the container

docker restart 8149bca96437

6. View the startup log

docker logs 容器ID

7. Linux memory is insufficient

docker run -e JVM_XMS=256m -e JVM_XMX=256m --env MODE=standalone --name nacos -d -p 8848:8848 nacos/nacos-server

Guess you like

Origin blog.csdn.net/BruceLiu_code/article/details/114636383