background:There is a flask project that provides an interface, which is built and run using a docker container. MySQL runs on the host machine, and you need to allow flask to connect to the host machine's mysql in the container. Using the ifconfig command, you can see that there is a docker0 and eth0. In the docker container, you can connect to the host's MySQL through the IP address of eth0 plus the port number (3306); in addition, nginx can access the container through the IP address of docker0 plus the port number specified when building the container. Supplement: The mysql container of docker runs normally, but the host machine cannot connect to the database. Here is the solution Docker runs mysql container normally, but host Navicat cannot connect I executed docker ps on docker and the display was as follows: This means that my mysql is normal, but I can't connect to my database using sqlyog and Navicat. Later I found the problem. Although I succeeded in creating a mysql container (docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.6.35), there was a prompt that I neglected: It is prompted here that the network is unavailable, so the host cannot connect to the database Solution: Now enter this command vim /usr/lib/sysctl.d/00-system.conf (if vim doesn't work, just enter vi): This will appear immediately: Add this sentence at the end: net.ipv4.ip_forward=1 (the added command is as follows: press the i key first, then you can operate) and then save and exit (after writing the command net.ipv4.ip_forward=1, press the esc key, then Ctrl+: and finally enter wq! to save and exit), then restart the network service: systemctl restart network First stop the mysql container just now docker stop docker, then delete the container docker rm mysql as follows: Now you can recreate the mysql container and see the effect: Is there no warning about the network being unavailable? I connected using sqlyog, and it was the same when I connected using Navicat: The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me. You may also be interested in:
|
<<: Some lesser-known sorting methods in MySQL
>>: js array entries() Get iteration method
Following are the quick commands to clear disk sp...
Preface The general methods are not listed here, ...
Preface I recently encountered a problem at work....
This article shares the specific code for WeChat ...
This article example shares the specific code of ...
Install ssh tool 1. Open the terminal and type th...
Scenario 1: Html: <div class="outer"...
This article takes the connection error ECONNREFU...
Table of contents 1. What is lazy loading? 2. Imp...
Don't be surprised if you see some kind of und...
1. Usage of instanceof instanceof operator is use...
NTP is a TCP/IP protocol for synchronizing time o...
A few days ago, when I was adjusting a module of a...
Mysql supports 3 types of lock structures Table-l...
1. Preparation 1.1 Download the Python installati...