I'm learning a little about Docker, but I had some problems connecting to 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
Here is the error message:
SQLSTATE[HY000] [2002] Connection refused
And the index.php code
<?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 :)