【发布时间】:2018-09-30 09:21:48
【问题描述】:
我是 docker 的初学者。 我可以登录到我的 mysql 容器并访问数据库。 但我无法从我的 PHP 容器访问它,当我尝试从 mysql 客户端(sequelPro)连接时也无法访问它。
PHP DockerFile
FROM php:7.0-apache
RUN apt-get update && \
apt-get install -y libfreetype6-dev libjpeg62-turbo-dev && \
docker-php-ext-install mysqli && \
docker-php-ext-install mbstring && \
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --
with-jpeg-dir=/usr/include/ && \
docker-php-ext-install gd
COPY ./php.ini /usr/local/etc/php/
RUN a2enmod rewrite
RUN service apache2 restart
docker-compose.yml
version: '2'
services:
mysql:
image: mysql:5.7
ports:
- "4407:3306"
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=shutterfly
shutterfly:
build: ./shutterfly
volumes:
- ./shutterfly:/var/www/html/
depends_on:
- mysql
restart: always
links:
- mysql
ports:
- "8000:80"
CodeIgnitor 给我这个错误:
Severity: Warning
Message: mysqli::real_connect(): (HY000/2002): Connection refused
Filename: mysqli/mysqli_driver.php
Line Number: 201
Backtrace:
File: /var/www/html/index.php
Line: 315
Function: require_once
Unable to connect to your database server using the provided settings.
Filename: core/CodeIgniter.php
Line Number: 518
在我的 Database.php 我有
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => "0.0.0.0",
'database_user' => 'root',
'database_password' => 'root',
'databasename' => 'shutterfly',
'port' => '4407',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
你能告诉我我错过了什么吗?
【问题讨论】:
-
我尝试使用“mysql”而不是 0.0.0.0 ('hostname' => "0.0.0.0",) 但它不起作用。也尝试了 localhost,127.0.0.1 ,但没有运气:(
-
哦,我要重写
'hostname' => "mysql"作为答案... -
好的。请尝试
docker-compose logs mysql。结果如何? -
这是 mysqld 之前的注释和警告列表:准备连接。警告类似于 --pid-file 的不安全配置:路径中的位置 '/var/run/mysqld' 是可访问的给所有操作系统用户。考虑选择不同的目录。 'user' 条目 'root@localhost' 在 --skip-name-resolve 模式下被忽略。 'user' 条目 'mysql.session@localhost' 在 --skip-name-resolve 模式下被忽略。 'user' 条目 'mysql.sys@localhost' 在 --skip-name-resolve 模式下被忽略。 'db' 条目 'performance_schema mysql.session@localhost' 在 --skip-name-resolve 模式下被忽略。
-
mysql: [警告] 在命令行界面上使用密码可能是不安全的。欢迎使用 MySQL 监视器。命令以 ; 结尾或\g。您的 MySQL 连接 ID 是 3 服务器版本:5.7.23 MySQL Community Server (GPL) 版权所有 (c) 2000, 2018,Oracle 和/或其附属公司。版权所有。 Oracle 是 Oracle Corporation 和/或其附属公司的注册商标。其他名称可能是其各自所有者的商标。输入“帮助”;或 '\h' 寻求帮助。键入 '\c' 以清除当前输入语句。 mysql>
标签: php mysql docker docker-compose dockerfile