docker exec -it your_mysql bash Once inside, authorize the user to use the remote connection
Enter the password ziqin666 to connect to mysql
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’ IDENTIFIED BY ‘ziqin666’; GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘ziqin666’; GRANT ALL PRIVILEGES ON *.* TO ‘root’@’127.0.0.1’ IDENTIFIED BY ‘ziqin666’; FLUSH PRIVILEGES;
At this point you can use the client to connect to see. (Ensure that the port corresponding to the security group rule is enabled.)
Build the phP-FPM container
The preparatory work
Php.ini does not exist by default
Create the php.ini file and conf.d folder in the /home/app/phpfile folder
Create a container
1 docker run -p 9000:9000 –name your_phpfpm -v /home/app/html:/var/www/html -v /home/app/phpfile:/usr/local/etc/php – link your_mysql: PHP mysql – d: 5.6 – FPM Command description:
–name your_phpfpm: Name the container your_phpfpm. – v/home/app/HTML: / var/WWW/HTML: the host project directory in/home/app/HTML mounted to the container/var/WWW/HTML
Install pDO to test the database connection later, which can be done in the DOCker PHP container
docker-php-ext-install pdo_mysql
Installing other plug-ins can also use this approach
Add to php.ini
extension=php_curl.dll extension=php_gd2.dll extension=php_mysql.dll extension=php_mysqli.dll extension=php_pdo_mysql.dll extension=php_pdo_odbc.dll extension=php_pdo.dll If plug-ins are not enough, you need to customize your own image
Change the index. PHP file in /home/app/nginx/ WWW/on the host.
<? php echo phpinfo();
3, test the mysql link
Modified index. PHP
<? php //echo phpinfo(); $dbms=’mysql’; // Database type $host=’your_mysql’; // Database host name, where write mysql container name $dbport = ‘3306’; $dbName=’mysql’; // The database used $user=’root’; // Database connection user name $pass=’123456′; // The corresponding password $dsn=”$dbms:host=$host; port=$dbport; dbname=$dbName”;
try { $dbh = new PDO($dsn, $user, $pass); // Initialize a PDO object echo “successful<br/>”; You can also perform a search operation // foreach ($dbh->query(‘SELECT * from user’) as $row) { // print_r($row); Echo ($GLOBAL); To see these values // }
$dbh = null; } catch (PDOException $e) { die (“Error! : ” . $e->getMessage() . “<br/>”); } Accessing the IP to the correct output proves that our configuration is successful.