mysqldockerdocker-composexdebug

Docker failed to build


I am following this tutorial.

This tutorial provides the files on a GitHub account.

I called my directory DOCKER-PHP-MYSQL, and it resembles the following:

DOCKER-PHP-MYSQL
> db
  - Dockerfile
> src
  - index.php
> www
  - Dockerfile
development.env
docker-compose.yml

Now my code literally matches everything in the git repository, but for the sake of the argument, I will paste what I have in each file.

The DB Dockerfile:

FROM mysql:8.0

In src, the index.php file:

<?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!';
}   
?>

Here is the 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

Here is the development.env:

MYSQL_USER=sys_admin
MYSQL_PASSWORD=sys_password
MYSQL_ROOT_PASSWORD=root_password

And finally, the 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

The only difference is the fact that I called my main folder DOCKER-PHP-MYSQL and the tutorial called it tutorial-07.

With that said, I am receiving the following error in the terminal upon running the command "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

How can I fix this problem?


Solution

  • Upon removing the following lines from the www Dockerfile, I was finally able to connect to MySQL:

    RUN docker-php-ext-install xdebug
    RUN docker-php-ext-enable xdebug