Write in front
This semester took the "Software Process Management" course. The course requirement is to build a shopping mall system and use the corresponding project management tools. After the efforts of the group students, the final project has been written locally and needs to be deployed on the server given by the teacher. Then leave the deployment to me.
The first idea: the next tomcat, set port 8081, and the next mysql, set port 3307. (Because other students are also using this server, so the port number has to be changed)
however! ! After all, I just learned docker, so I decided to use tomcat container and mysql container to do this .
Step 1: Download and start the container
Refer to the blog I wrote: https://blog.csdn.net/qq_37054755/article/details/117410591?spm=1001.2014.3001.5501 and proceed with the following steps:
docker pull mysql:5.7Download the 5.7 version of the docker image
docker run -p 3307:3306 --name mysql -v /root/group26/mydocker/mysql/conf:/etc/mysql/conf.d -v /root/group26/mydocker/mysql/logs:/logs -v /root/group26/mydocker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7Start the mysql container
docker pull tomcatDownload the tomcat image
docker run -it -p 8081:8080 --name tomcat --link mysql:dbhost -v /root/group26/tomcat/webapps:/usr/local/tomcat/webapps tomcatStart the tomcat container
5. Put the war package in the corresponding webapps directory. At this time, remember to modify the jdbc connection as follows:
String DB_URL = "jdbc:mysql://mysql:3306/tmsshopping?serverTimezone=UTC&useSSL=false&userUnicode=true&allowPublicKeyRetrieval=true";
Because the name of our mysql container is mysql, we write the address
mysql:3306. Note that it is not
mysql:3307, because the port corresponding to the container is 3306.
Step 2: Solve the problem that the database cannot be entered in Chinese
I clicked on the webpage and found that all Chinese were gone. I checked the database again and found that all the places that should be Chinese were empty. I don't know if it became a space or what.
1. I searched the Internet and found that the configuration file is to be modified as follows:
# dvice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] character-set-server=utf8 # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [client] default-character-set=utf8
In fact, it is added under [mysqld] and under
[Note] This configuration file should be named
my.cnfand placed in a
/etcfolder in the container .
2. At this time, enter the mysql container, the command is
docker exec -it mysql /bin/bash, then enter mysql, enter the command to check the character set, and
show variables like '%char%'
find that the others are all urf8,
ALTER DATABASE tmsshopping CHARACTER SET utf8
This is all utf8.
3. However! ! Or not! ! Finally, I saw what terminal code or something, that is, it is best not to directly copy the SQL statement to build the database, but to build the database with
So, put the tmsshopping.sql file in the /bin directory of the mysql container, build the database, and finally succeed! !
to sum up
Docker is a good thing, otherwise, configure the environment variables of tomcat or something. After using the docker container, the tomcat container exposes port 8080 (8081 of the host), and mysql exposes port 3306 (3307 of the host), and then connect the two containers! !