5
MySQL 컨테이너에 연결하는 데 문제가 있습니다.Docker PHP, MySQL, nginx 연결 문제로 작성하십시오
고정 표시기 - 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 테스트 스크립트 :
<?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();
}
?>
이 스크립트는 나를 reponse는 :
Connection failed: SQLSTATE[HY000] [2002] No such file or directory
내 코드에 어떤 문제가 있습니까? 왜냐하면 나는 그것이 괜찮을 것이라고 생각하기 때문이다.
누구든지 더 나은 해결책을 가지고 있다면 도움을 주셔서 감사합니다.
여전히 동일한 답변을 가지고 있습니다. – wiput1999
감사합니다. D – wiput1999