2
I’m learning a little about Docker, but I had some problems connecting with Mysql.
Follow the file Docker-Compose.yml
php:
build: .
ports:
- "8082:80"
volumes:
- ./www:/var/www/html
links:
- db
db:
image: mysql:5.7
ports:
- "3306:3306"
volumes:
- ./var/lib/mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=phprs
- MYSQL_DATABASE=phprs
And the Dockerfile file
FROM php:5.6-apache
RUN docker-php-ext-install mysqli pdo_mysql mysql pdo
Follow the error message:
SQLSTATE[HY000] [2002] Connection refused
And the code of index.php
<?php
define( 'MYSQL_HOST', '127.0.0.1' );
define( 'MYSQL_USER', 'root' );
define( 'MYSQL_PASSWORD', 'phprs' );
define( 'MYSQL_DB_NAME', 'phprs' );
try
{
$PDO = new PDO( 'mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DB_NAME . ';port=3306', MYSQL_USER, MYSQL_PASSWORD );
}
catch ( PDOException $e )
{
echo 'Erro ao conectar com o MySQL: ' . $e->getMessage();
}
How do I view the mysql, and apache error logs?
Thank you guys :)
Thank you very much Leonancarvalho worked!
– Samuel Gomes