Install MySql database
1. Search the mysql image on hub.docker.com
2. Pull the specified version of mysql. You can also specify the pull version, for example:
docker pull mysql:8.0.23
3. Check mysql image
docker images
4. Start and run mysql image (docker run is used to start a container)
sudo docker run -p 3306:3306 --name mysql \ -v /usr/local/docker/mysql/mysql-files:/var/lib/mysql-files \ -v /usr/local/docker/mysql/conf:/etc/mysql \ -v /usr/local/docker/mysql/logs:/var/log/mysql \ -v /usr/local/docker/mysql/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:8.0.23
If the installation fails, you can view the previous container through docker ps -a. if it already exists, you can delete it through docker rm image id and reinstall it
Log in to mysql service
1. Enter the container (exit for exiting the container)
sudo docker exec -it mysql bash
2. When logging in (the default password is root), be sure to enter the mysql container first.
mysql -uroot -proot
Stop and start mysql service
docker stop/start mysql
Set mysql startup and self startup
docker update mysql --restart=always
Install Redis database
1. Download the image file
docker pull redis
2. Prepare the configuration file
mkdir -p /usr/local/docker/redis01/conf
Create a redis.conf configuration file under the configuration file record (this file must be created. No, a directory is generated by default when we mount the directory)
touch /usr/local/docker/redis01/conf/redis.conf
3. Create a redis instance and start it
sudo docker run -p 6379:6379 --name redis01 \ -v /usr/local/docker/redis01/data:/data \ -v /usr/local/docker/redis01/conf/redis.conf:/etc/redis/redis.conf \ -d redis redis-server /etc/redis/redis.conf
Access redis server
1. The console is directly connected to the redis test
docker exec -it redis01 bash
2. Check redis version
redis-server -v
or
redis-cli -v
3. Log in to redis (no password is required by default)
redis-cli
Or you can directly combine the above two steps into one step. The instructions are as follows:
docker exec -it redis01 redis-cli
Stop and start redis service
Stop redis service?
docker stop redis01
Start redis service?
docker start redis01
Restart redis service?
docker restart redis01
Install Nginx agent
1. Pull the nginx image (find it from hub.docker.com)
docker pull nginx
2. Create a data volume (this object will directly create a directory on the host)
docker volume create nginx-vol
To view the host directory corresponding to the data volume, you can use the following instructions:
docker inspect nginx-vol
3. Start nginx service
docker run --name nginx -p 80:80 -v nginx-vol:/etc/nginx -d nginx
Where: / etc/nginx is the default decompression directory of nginx image files when the nginx container is started
Note: if you want to modify the nginx configuration in the future, you can modify it directly in the directory corresponding to the nginx Vol data volume
Installing Nacos components
1. Pull nacos (hub.docker.com)
docker pull nacos/nacos-server:1.4.1
2. Execute the sql script file of nacos in MySQL
1) Copy the file nacos-mysql.sql (which can be downloaded from the code server) to the mount directory corresponding to the host of the MySQL container (you can view your MySQL mount directory through docker inspect mysql)
2) Start and log in to mysql in linux environment
Enter mysql container (if mysql has been started)
docker exec -it mysql bash
Login to mysql
mysql -uroot -p
Run the sql file in the container directory through the source command
source /etc/mysql/nacos-mysql.sql #Here, / etc/mysql is a directory in the container (select the directory you want to mount)
3. Create and start the nacos container (when copying the following contents, the account and password should use their host ip and their own database account and password)
docker run \ -e TZ="Asia/Shanghai" \ -e MODE=standalone \ -e SPRING_DATASOURCE_PLATFORM=mysql \ -e MYSQL_DATABASE_NUM=1 \ -e MYSQL_SERVICE_HOST=192.168.126.129 \ -e MYSQL_SERVICE_PORT=3306 \ -e MYSQL_SERVICE_USER=root \ -e MYSQL_SERVICE_PASSWORD=root \ -e MYSQL_SERVICE_DB_NAME=nacos_config \ -p 8848:8848 \ --name nacos \ --restart=always \ -d nacos/nacos-server:1.4.1
Parameter description
- Single node mode
MODE=standalone - Database address
MYSQL_SERVICE_HOST - Database user name
MYSQL_SERVICE_USER - Database password
MYSQL_SERVICE_PASSWORD - Name of database to be connected
MYSQL_SERVICE_DB_NAME - Port mapping
-p 8848:8848 - Restart the container at any time, and the container can be started automatically (docker needs to be set to start automatically)
--restart=always