Categorize and comb through the components required by the environment in which the project is run

Persistent component

Environment: Docker-Library /mysql 5.7

Note: here just take mysql as an example, the essence such as Redis, Rabbitmq, MongoDB these components can follow the following ideas

Start the instruction

[root@localhost ~]# docker run -d --name mysql02 -v mysql02_volume:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=mysql123 mysql    
Copy the code

Check the mysql02

[root@localhost ~]# docker volume inspect mysql02_volume  
Copy the code

A detailed analysis

attribute instructions
Volume See mysq’s dockerfile for information about where data is stored in the container after the container is started
Mountpoint The path information for storing data in the host computer can be understood as the mapping relationship between the host computer and the folder where the data is stored in the container
instruction instructions
docker volume ls The name of the folder in the host where the data is stored
-v mysql02_volume:/var/lib/mysql Customize the volume name to increase readability

Summary: We need to define our own easy to remember and recognize names for the persistent containers we create

The default directory for volume is /var/lib/docker/volumes/, where a series of folders such as mysql and Redis are stored

Server component

Start the instruction

[root@localhost ~]#Docker pull Tomcat :8.5 [root@localhost ~]#Docker run - d - p - 8097-8080 - v/data/sbproject: / usr/local/tomcat/webapps/sbproject - name tomcat01 tomcat: 8.5Copy the code

Check the tomcat01

docker inspect tomcat01
Copy the code
 "Mounts": [
            {
                "Type": "bind",
                "Source": "/data/sbproject",
                "Destination": "/usr/local/tomcat/webapps/sbproject",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
Copy the code

A detailed analysis

attribute instructions
Source Host project The path to the project, such as a WAR or jar, can be an H5
Destination The path to the starting location of the project in the container

Go to /data/ sbProject and create a test.html file

[root@localhost webapps]# cd /data/sbproject/
[root@localhost sbproject]# vim test.html

Copy the code

Go to the sbProject folder in the Tomcat01 container

[root@localhost ~]# docker exec -it tomcat01 bash 
root@d5a16581af1e:/usr/local/tomcat# cd webapps/sbproject/
root@d5a16581af1e:/usr/local/tomcat/webapps/sbproject# ls -ll
total 4
-rw-r--r--. 1 root root 32 Jun  6 13:40 test.html
root@d5a16581af1e:/usr/local/tomcat/webapps/sbproject# 
Copy the code

The test results