在this tutorial之后。
本教程在GitHub account上提供了文件。
我将目录命名为DOCKER-PHP-MYSQL,它类似于以下内容:
DOCKER-PHP-MYSQL
> db
- Dockerfile
> src
- index.php
> www
- Dockerfile
development.env
docker-compose.yml
现在我的代码从字面上匹配git存储库中的所有内容,但是出于参数的考虑,我将粘贴每个文件中的内容。
DB Dockerfile:
FROM mysql:8.0
在src中,为index.php文件:
<?php
$mysqli = new mysqli('tut07-db', getenv('MYSQL_USER'), getenv('MYSQL_PASSWORD'), 'information_schema');
if ($mysqli->connect_error)
{
echo 'Connection Error [', $mysqli->connect_errno, ']: ', $mysqli->connect_error;
}
else
{
echo 'MySQLi Connected Successfully!';
}
?>
这是www Dockerfile:
FROM php:7.2-apache
RUN docker-php-ext-install mysqli
RUN docker-php-ext-enable mysqli
RUN docker-php-ext-install xdebug
RUN docker-php-ext-enable xdebug
这是development.env:
MYSQL_USER=sys_admin
MYSQL_PASSWORD=sys_password
MYSQL_ROOT_PASSWORD=root_password
最后是docker-compose.yml:
version: "3"
networks:
tut07-frontend:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.10.1.0/24
tut07-backend:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.10.2.0/23
services:
tut07-db:
build: ./db
command: --default-authentication-plugin=mysql_native_password
ports:
- 3306:3306
networks:
tut07-backend:
ipv4_address: 172.10.3.2
env_file:
- ./development.env
tut07-www:
build: ./www
ports:
- 8080:80
volumes:
- ./src:/var/www/html/
networks:
tut07-backend:
ipv4_address: 172.10.2.2
tut07-frontend:
ipv4_address: 172.10.1.2
depends_on:
- tut07-db
env_file:
- ./development.env
唯一的区别是,我将主文件夹命名为DOCKER-PHP-MYSQL,而本教程将其命名为tutorial-07。
话虽如此,我在运行命令“ docker-compose up”时在终端中收到以下错误:
error: /usr/src/php/ext/xdebug does not exist
usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name ...]
ie: /usr/local/bin/docker-php-ext-install gd mysqli
/usr/local/bin/docker-php-ext-install pdo pdo_mysql
/usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop
if custom ./configure arguments are necessary, see docker-php-ext-configure
Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zend_test zip
Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.
ERROR: Service 'tut07-www' failed to build: The command '/bin/sh -c docker-php-ext-install xdebug' returned a non-zero code: 1
有人知道这个问题以及如何解决吗?
答案 0 :(得分:0)
从www Dockerfile删除以下行后,我终于能够连接到MySQL:
RUN docker-php-ext-install xdebug
RUN docker-php-ext-enable xdebug