Исправь ошибки : adduser@IvanThunder:~/project$ tree
.
├── Dockerfile-php
├── apache
│   └── apache2-config
├── cat-files.sh
├── docker-compose.yml
├── init-db.sql
├── init.sql
├── mysql
│   └── Dockerfile-mysql
├── mysql-data
│   ├── auto.cnf
│   ├── ca-key.pem
│   ├── ca.pem
│   ├── client-cert.pem
│   ├── client-key.pem
│   ├── ib_buffer_pool
│   ├── ib_logfile0
│   ├── ib_logfile1
│   ├── ibdata1
│   ├── mydb  [error opening dir]
│   ├── mysql  [error opening dir]
│   ├── mysql.sock -> /var/run/mysqld/mysqld.sock
│   ├── performance_schema  [error opening dir]
│   ├── private_key.pem
│   ├── public_key.pem
│   ├── server-cert.pem
│   ├── server-key.pem
│   └── sys  [error opening dir]
└── www
    ├── add.php
    ├── config.php
    ├── index.php
    └── orders.php

9 directories, 24 files
adduser@IvanThunder:~/project$ ./cat-files.sh
find: ‘./mysql-data/performance_schema’: Permission denied
find: ‘./mysql-data/mysql’: Permission denied
find: ‘./mysql-data/mydb’: Permission denied
find: ‘./mysql-data/sys’: Permission denied
File: ./init.sql
CREATE TABLE users (
  id INT(11) NOT NULL AUTO_INCREMENT,
  name VARCHAR(50),
  email VARCHAR(50),
  PRIMARY KEY (id)
);

CREATE TABLE orders (
  id INT(11) NOT NULL AUTO_INCREMENT,
  user_id INT(11),
  product_name VARCHAR(50),
  price FLOAT(2),
  PRIMARY KEY (id),
  FOREIGN KEY (user_id) REFERENCES users(id)
);
File: ./www/add.php
<?php
include_once("config.php");

$message = "";

if(isset($_POST['submit'])) {
  $name = $_POST['name'];
  $email = $_POST['email'];

  if(empty($name) || empty($email)) {
    $message = "<p>Please provide name and email</p>";
  } else {
    if($stmt = $mysqli->prepare("INSERT INTO users(name,email) VALUES(?,?)")) {
      $stmt->bind_param("ss", $name, $email);

      if($stmt->execute()) {
        $message = "<p>User added successfully</p>";
      } else {
        $message = "<p>Error: " . $mysqli->error . "</p>";
      }

      $stmt->close();
    } else {
      $message = "<p>Error: " . $mysqli->error . "</p>";
    }
  }
}
?>

<form method="post">
  <?php echo $message; ?>
  <label>Name:</label>
  <input type="text" name="name">
  <br>
  <label>Email:</label>
  <input type="text" name="email">
  <br>
  <input type="submit" name="submit" value="Add">
</form>

<a href="index.php">Back to list</a>
File: ./www/orders.php
<?php
include_once("config.php");

if(isset($_GET['id'])) {
  $user_id = $_GET['id'];

  if($stmt = $mysqli->prepare("SELECT * FROM orders WHERE user_id=?")) {
    $stmt->bind_param("i", $user_id);

    if($stmt->execute()) {
      $result = $stmt->get_result();

      if($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
          $data[] = $row;
        }

        header("Content-type: application/json");
        echo json_encode($data);
      } else {
        echo "<p>No orders found for user with id {$user_id}</p>";
      }
    } else {
      echo "<p>Error: " . $mysqli->error . "</p>";
    }

    $stmt->close();
  } else {
    echo "<p>Error: " . $mysqli->error . "</p>";
  }
} else {
  echo "<p>Please provide user id</p>";
}
?>
File: ./www/config.php
<?php
$dbhost = 'db';
$dbname = 'mydatabase';
$dbuser = 'myuser';
$dbpass = 'mypassword';


$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($mysqli->connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli->connect_error;
  exit();
}
?>
File: ./www/index.php
<?php
include_once("config.php");

if ($result = $mysqli->query("SELECT * FROM users")) {
  if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
      echo "<p>{$row['id']}: {$row['name']}</p>";
    }
  } else {
    echo "<p>No users found</p>";
  }
} else {
  echo "<p>Error: " . $mysqli->error . "</p>";
}
?>

<a href="add.php">Add user</a>
File: ./Dockerfile-php
FROM ubuntu:latest
RUN apt-get update

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Moscow

RUN apt-get install -y apache2 php libapache2-mod-php tzdata

RUN a2enmod rewrite

RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/*/apache2/php.ini

RUN apt-get install -y php-mysql && phpenmod mysqli

COPY ./www /var/www/html

EXPOSE 80
CMD ["apache2ctl", "-D", "FOREGROUND"]
File: ./docker-compose.yml
version: '3'
services:
  db:
    build:
      context: .
      dockerfile: ./mysql/Dockerfile-mysql
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

  web:
    depends_on:
      - db
    build:
      context: .
      dockerfile: Dockerfile-php
    ports:
      - "8080:80"
    restart: always
    volumes:
      - ./apache/apache2-config:/etc/apache2/sites-available/000-default.conf
    environment:
      - APACHE_RUN_USER=www-data
      - APACHE_RUN_GROUP=www-data
      - APACHE_LOG_DIR=/var/log/apache2
      - APACHE_PID_FILE=/var/run/apache2/apache2.pid
      - APACHE_RUN_DIR=/var/run/apache2
      - APACHE_LOCK_DIR=/var/lock/apache2

volumes:
  db_data:
File: ./cat-files.sh
#!/bin/bash

for file in $(find . -type f)
do
    echo "File: $file"
    cat $file
done
File: ./init-db.sql
USE mydb;

CREATE TABLE users (
  id INT(11) NOT NULL AUTO_INCREMENT,
  name VARCHAR(50),
  email VARCHAR(50),
  PRIMARY KEY (id)
);

CREATE TABLE orders (
  id INT(11) NOT NULL AUTO_INCREMENT,
  user_id INT(11),
  product_name VARCHAR(50),
  price FLOAT(2),
  PRIMARY KEY (id),
  FOREIGN KEY (user_id) REFERENCES users(id)
);
File: ./mysql/Dockerfile-mysql
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y mysql-server
EXPOSE 3306
COPY init-db.sql /docker-entrypoint-initdb.d/
CMD ["mysqld"]
File: ./mysql-data/server-key.pem
cat: ./mysql-data/server-key.pem: Permission denied
File: ./mysql-data/auto.cnf
cat: ./mysql-data/auto.cnf: Permission denied
File: ./mysql-data/ib_buffer_pool
cat: ./mysql-data/ib_buffer_pool: Permission denied
File: ./mysql-data/ib_logfile1
cat: ./mysql-data/ib_logfile1: Permission denied
File: ./mysql-data/server-cert.pem
adduser@IvanThunder:~/project$