Before installation, you need to prepare a mysql. The current installation method is to persist the data in the database. The deployment here is a stand-alone mode.
1. Docker pulls the image
docker pull nacos/nacos-server
PS: This is to pull the latest nacos version. If you need to pull other versions, you can add: version number (eg: docker pull nacos/nacos-server:v2.2.0)
PS: The purpose of starting nacos in this step is to copy the files in nacos to the mount directory, so that we can directly modify the files in the mount directory to map them into the container
4. Create the tables required for nacos in mysql
Create a new library in mysql, the name can be customized, here use nacos-config
Find the table creation file from github , execute it in the nacos-config library, and create the required table
PS : Copying the above statement fails to execute, you can change the above execution statement into one line, as follows, you can directly copy and execute
docker run -d: Start the container -d means to start in the background and return the container id
--name nacos : specify a name for the container
-p 8848:8848 -p 9848:9848 -p 9849:9849: Specify the port mapping, note that the p here cannot be capitalized, the capitalization is a random port mapping
–privileged=true : Expand the permissions in the container, and change the permissions in the container to root permissions. If you don’t add it, it will be ordinary user permissions, and you may not open directory
-e JVM_XMS=256m : memory allocated for jvm startup
-e JVM_XMX=256m : The maximum memory allocated for jvm running
-e MODE=standalone: Use standalone mode (stand-alone mode), the MODE value has two types: cluster (cluster) mode/standalone mode, and MODE must be capitalized
-v /mydata/nacos/logs/:/home/nacos/logs : Mount the /home/nacos/logs directory of the container to /mydata/nacos/logs
-v /mydata/nacos/conf/:/home/nacos/conf/: Mount the /home/nacos/conf directory of the container to /mydata/nacos/conf
–restart=always : When restarting docker, automatically start the relevant container
Precautions
Relevant ports need to be opened on the firewall. If you are a cloud server, open the security group, and provide relevant statements below
PS: There is a small problem here. After restarting the firewall, you need to restart docker
## 重启docker
systemctl restart docker
The easiest thing to make a mistake here is that the mount directory does not match. You can check whether the directory after -v in your statement is mapped correctly. When the blogger installed it for the first time, there was a logs folder in the logs, and there was also a log folder in the conf. conf folder, resulting in an error
6. Modify the configuration file
The main modification is the application.properties file
## 在宿主机中修改application.properties文件
vim /mydata/nacos/conf/application.properties
Where the file is modified (modified to your corresponding mysql)
PS: Because we have copied the logs and conf to our host machine in the third step, then we can directly modify the application.properties file and map it to the container, which can be viewed through the following statement
PS: If the file is not modified successfully, it means that the mounting directory mapping is incorrect. Check it carefully. You can use the following method to check whether it is correct
docker inspect --format="{
{json .Mounts}}" nacos
7. Visit the page
http://ip:8848/nacos/index.html
8. Finally
Leave a message if you have any questions, I will reply