Ich habe ein Problem mit dem MySQL-Container verbinden.Docker Compose mit PHP, MySQL, Nginx Verbindungsproblem
Docker-compose.yml
version: '2'
services:
mysql:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: JoeyW#1999
MYSQL_DATABASE: wiput
MYSQL_USER: web
MYSQL_PASSWORD: Web#1234
volumes:
- ./mysql:/var/lib/mysql
networks:
- code-network
php:
image: wiput1999/php:latest
volumes:
- ./code:/code
networks:
- code-network
nginx:
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./code:/code
- ./site.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt:/etc/letsencrypt
networks:
- code-network
networks:
code-network:
driver: bridge
PHP Testskript:
<?php
$servername = "localhost";
$username = "root";
$password = "JoeyW#1999";
try {
$conn = new PDO("mysql:host=$servername;dbname=wiput", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
Dieses Skript mich Réponse:
Connection failed: SQLSTATE[HY000] [2002] No such file or directory
Was mit meinem Code falsch? weil ich denke, es sollte in Ordnung sein
Wenn jemand eine bessere Lösung haben Vielen Dank für Ihre Hilfe.
Immer noch die gleiche Antwort – wiput1999
Es ist Arbeit jetzt Vielen Dank: D – wiput1999