Connection between two containers in docker---centos7 container + mysql container

centos7 container: It is the container where the software is installed before, including jdk, matlab, redis, tomcat

mysql container: mysql5.7

1. First create the mysql container:

docker run --name=mysql -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d docker.io/mysql:5.7

start the mysql container

docker exec -it mysql bash  

Remarks: The above can be combined and written in one piece

Test that the external sqlyong connection software can connect to mysql.

2. Start the centos7 container again

docker run --privileged=true -t -i -v /opt:/opt -p 8081:8080 -p 6379:6379 02abcd2234 /bin/bash

The mysql link address of the project configuration in tomcat is:

ip is the ip address of the host machine (it can be connected through sqlyong)

3. Enter the tomcat startup project and report an error:

According to the analysis on the Internet, the container interconnection needs to add a link command, so shut down the centos7 container and delete it, and open the centos7 container again

docker run --privileged=true -t -i -v /opt:/opt -p 8081:8080 -p 6379:6379 --link mysql:mysql 02abcd2234 /bin/bash

Note: mysql:mysql followed by --link, the first mysql is the name of the mysql container started (--name=mysql), and the latter is the added alias, which is used to configure the link address for tomcat.

At the same time, enter the project to modify the jdbc link address (replace ip with the name of the mysql container specified by link, the port is mapped to the external port in time, and the port of the mysql container must also be used, that is, if 33066 is mapped, but also use 3306 port Just do it.)

Note: redis and tomcat are in a container, when configuring the ip of redis, it can be set to 127.0.0.1 (even if remote access is enabled, it seems that the configuration file in the container does not take effect)

4. Start toncat and find that mysql can be linked.

Note: But after running the project, I found that some sql statements reported errors, which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by error,

This is because we are using mysql5.7,

So you can modify sql_mode by executing the statement

SET GLOBAL sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
  
SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325275321&siteId=291194637