0

I want to use Docker with APACHE, PHP, MYSQL projects with files structure like in Laravel where there is a 'public' folder with a public files and all of the apps files are one level higher in.ex. app, modules, node, vendor etc. I can setup docker-compose.yml file and Dockerfile to create docker container with APACHE-PHP, MYSQL and PHPMYADMIN and it's working but all of files one level higher that WORKDIR is unavailable.

My problem is I can't setup this container to properly use my app. Simple PHP script below is not working. What should I do?

[public/index.php]

<?php
echo "index.php";
require_once __DIR__ . "/../include.php";

[docker-compose.yml]

version: '3.9'

services:
  php-env:
    build: .
    volumes:
      - ./public:/var/www/html
    ports:
      - 8000:80

  mysql-db:
    image: mysql:latest
    ports:
      - 3306:3306    
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_DATABASE: ${DB_NAME}    
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASS}
      MYSQL_ROOT_PASSWORD: ${DB_PASS}

[Dockerfile]

FROM php:8.1-apache
WORKDIR /var/www/html
RUN apt-get update -y && apt-get install -y libmariadb-dev
RUN docker-php-ext-install mysqli
Dharman
  • 30,962
  • 25
  • 85
  • 135
Sandowl
  • 73
  • 1
  • 4
  • Can't remember the details as this works at home - the principle is that the directory you need to access MUST be mounted in the container. Inside the container you then need to tell it that the root of the web site is in a subdirectory of your mount point. – Nigel Ren Aug 08 '22 at 11:27
  • OK but how to do this? I don't know if I'm understand correctly but should I set up this in 000-default.conf in Apache. – Sandowl Aug 08 '22 at 11:53
  • @NigelRen Your advice to change mount point in the container was very good. I've change the default domain folder to /public and that's all. Thanks for help. – Sandowl Aug 09 '22 at 12:56
  • Could be worth writing it as an answer. – Nigel Ren Aug 09 '22 at 13:10

0 Answers0