review:
Web development foundation of SpringBoot
SpringBoot Web Development Experiment
Follow-up processing of SpringBoot web development
Introduction
Docker is an open source application container engine; it is a lightweight container technology;
Docker supports compiling software into a mirror; then configure various software in the mirror and publish the mirror, and other users can use the mirror directly; similar to the principle of the ghost system.
Key concept
1) Install linux system (by Baidu)
2) Install docker on linux system
① Check the kernel version (3.10 and above), use the command uname -r to view
② Install docker yum install docker
View version:
③ 启动docker systemctl start docker
If it fails to start, enter the /etc/sysconfig/ directory, edit the selinux file, and change the attribute value of selinux to disabled.
④ Query command (such as docker search mysql )
⑤ Download the image (docker pull <image name [can be the full name or abbreviation, such as: full name [docker.io/mysql], abbreviation [mysql]]>)
⑥ Specify the version of the downloaded image (the default is the latest version [latest]): docker pull <image name>:<version name>
⑦ Query docker images ( docker images )
⑧ Delete the specified mirror (docker rmi <mirror id>)
Container operation
Process: Identify the required image ==> run the image ==> generate the corresponding container (the software itself, such as tomcat)
Search mirror: docker search tomcat
Pull the image: docker pull tomcat (default is the latest version)
Start the container: docker run --name <custom container name, such as: mytomcat> -d[represents background operation] <image name>[can add version number]
docker run --name mytomcat -d tomcat:latest
View running/all images (software): docker ps / docker ps -a
Stop the running container: docker stop <id of running container>
When you know the container id, you can also use the command docker start <container id> to start the container
Delete the container, docker rm <container id>
External access to tomcat's docker container (do port mapping)
Command: docker run --name <custom container name> -d -p <virtual machine port>:<port to be mapped to tomcat> <tomcat image name>
Example: Map the port 8888 of the virtual machine to port 8080 of tomcat, so that the outside can access port 8080 of tomcat through port 8888
Access: ip:8888 Before this, you need to turn off the Linux firewall
View container logs: docker logs <container id>
One image can start multiple containers
More commands: https://docs.docker.com/engine/reference/commandline/docker/
Install and start mysql
Install the mirror, refer to the above, start the mirror, refer to the official document
docker run --name mysql01 -e MYSQL_ROOT_PASSWORD=<custom password> -d mysql
-p: do port mapping
-e: Specify the password of the root account
-d: run in the background
Connection test:
ps: If the connection is unsuccessful and error code 2059 is reported, please refer to the solution: https://blog.csdn.net/u013274055/article/details/83794340
step:
① Query specific mysql container id: docker ps -a
② Connect to the docker container of mysql: docker exec -it [specify container id] bash
③ Connect to mysql: mysql -u root -p
④ Modify the encryption method to mysql_native_password, and the password to root: alter user'root '@'%' identified with mysql_native_password by'root'
⑤ Execute the command to make the permission configuration item take effect immediately: flush privileges
Other advanced operations
Official document description:
Interpretation:
docker run --name [custom mysql name] -e MYSQL_ROOT_PASSWORD=[custom root account password] -d mysql:[specified version, default latest version] --character-set-server=utf8mb4 --collation-server= utf8mb4_unicode_ci (the red part is the specified encoding as utf-8)
docker run --name mysql_name -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
It means that the encoding of mysql is utf-8
docker run --name [Custom Name] -v [Custom Folder]: /etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD = [self-defined root account password] -d mysql: [specified version]
docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
It means to mount the [specified folder] of the host to the /etc/mysql/conf.d folder of the mysql docker container , so that you only need to put the mysql configuration file in a custom folder in the future. (The docker container will be integrated with the original configuration file of mysql)